View Full Version : ExtJS 4, related models and forms

23 Aug 2011, 10:29 PM
I would like to create a form that can be used to edit hierarchical data.

If I have for example following data:

{ "name" : "foo",
"somedata" : 123,
"extrainfo" : {
"name" : "bar",
"otherdata": 888

And I would like to have a form that contains fields for: "name", "somedata", "extrainfo.name" and "extrainfo.otherdata". And preferably so that I can set/get values by using loadRecord and getRecord methods on a form.

Closest thing I managed to make was to add fields as "extrainfo.name" (exactly like that) in the mian model but that kind of destroys the idea of using two models with properly set relation(s).

24 Aug 2011, 12:24 AM
I may be way off here, but my understanding of the ExtJS model relationships is that there is not proper support for 1-1 relationships, only 1-many. In the context of a 1-many relationship the idea of populating a form doesn't really make sense as far as I can tell. I think the 'correct' way to do this is to merge your 2 models into 1.

Like I said, I might be completely wrong. I've seen a lot of people ask effectively the same question over the last few weeks (usually trying to populate a grid rather than a form) but I've not seen anyone give a working solution that used multiple models.

24 Aug 2011, 9:28 PM
Since one to one relation is basically special case of one to many that shouldn't affect outcome.

More over I probably would like to have form that could contain also multiple entries from child records.

Grids are pretty simple since they require store where data is and related entries do have stores.

With 4.0.2a you can do grid.bindStore(mymodel.somerelation()) (There is a bug that is fixed in 4.0.3 in grid.reconfigure that would be better option.)

It would be useful to have way to define form fields with hierarchy so that even using "form.getValues()" would return hierarchical data.

Like if I define field name like "myobj.id" form.getValues() would interpret that as a

{ "myobj" : { "id" : value }}