How to set combox value on form from grid with nested data? Extjs 4.2 Mvc -
i have grid pops edit form combobox. before show view load combobox store. set values of form using form.loadrecord(record);
. loads primary record ok. how load associated data value tied combobox combobox's value set correctly.
i know can use setvalue manually, guess thinking handled via load form.
if form has 3 fields lets firstname lastname , combobox of contacttype. firstname , lastname in primary record contacttype being associated record. if change values in fields lastname or firstname change detected , record marked dirty. if change combobox value record not marked dirty. guessing because 2 different models. how make 1 record. think having combobox on form has values set record in grid common can't find examples of best way accomplish this.
here code.
my json looks this. primary record has firstname lastname hasone associated record contacttype
{ "__entities":[ { "__key":"289", "__stamp":12, "id":289, "firstname":"a", "middlename":"", "lastname":"asd", "contacttype":{ "__key":"2", "__stamp":4, "id":2, "name":"home" } } ] }
controller list function,edit function , updatefunction, fires when grid row clicked
list: function () { var mystore = this.getstore('contacts') mystore.proxy.extraparams = { $expand: 'contacttype'}; mystore.load({ params: { }, callback: function(r,options,success) { // debugger; } //callback }); //store.load editcontact: function (grid, record) { //load store combobox var store = this.getstore('contacttypes'); store.load({ params: { }, callback: function(r,options,success) { // debugger; } //callback }); //store.load var view = ext.widget('contactsedit'); var form = view.down('form') //load primary record form.loadrecord(record); //load associated record form.loadrecord(record.getcontacttype()); updatecontact: function (button) { var win = button.up('window'), form = win.down('form'), record = form.getrecord(), values = form.getvalues(), store = this.getstore('contacts') if (form.getform().isvalid()) { if (this.addnew == true) { store.add(values); } else { record.set(values); } store.sync(); win.close(); } }
the loadrecord(record.getcontacttype)
getter associated data. able associated data not sure how make set value in combobox or how act 1 record , detect changes automatically.
my contacts model
ext.define('simplyfundraising.model.contact', { extend : 'wakanda.model', requires:[ 'simplyfundraising.model.contacttype' ], fields: ['firstname', 'middlename','lastname','contacttype.name'], associations: [ { type: 'hasone', model: 'simplyfundraising.model.contacttype', name: 'contacttypes', gettername: 'getcontacttype', associationkey: 'contacttype' } ] });
contacttype model
ext.define('simplyfundraising.model.contacttype', { extend : 'wakanda.model', fields: ['__key','name',] });
is proper way set value combobox in form nested data?
should not use associations , put fields in contact model ie add contacttype fields contact model, data should in same record , change tracking work. seems counter mvc pattern , counter reason associations.
how guys handle scenario, examples great!
thanks, dan
if form loading values correctly, need this:
Comments
Post a Comment