Extjs 4, checkbox forms and loadRecord

In my Extjs4 application, I have a grid and a shape.

User Model:

Ext.define('TestApplication.model.User', {
    extend: 'Ext.data.Model',
    fields: [
      { name: 'id', type: 'int', useNull: true },
      { name: 'email', type: 'string'},
      { name: 'name', type: 'string'},
      { name: 'surname', type: 'string'}
    ],
    hasMany: { model: 'Agency', name: 'agencies' },
});

And Agency:

Ext.define('Magellano.model.Agency', {
  extend: 'Ext.data.Model',
  fields: [
    {name: 'id', type: 'int', useNull: true},
    {name: 'name', type: 'string'}
  ]
});

Then in my form I create checkboxes:

[...]
  initComponent: function() {
    var store = Ext.getStore('Agencies');
    var checkbox_values = {xtype: 'checkboxfield', name: 'agencies[]'};
    var checkboxes = []

    store.each(function(record){
      var checkbox = {xtype: 'checkboxfield', name: 'agency_ids',
                      boxLabel: record.get('name'), inputValue: record.get('id')};
      checkbox.checked = true;
      checkboxes.push(checkbox)
    });
    this.items = [{
      title: 'User',
      xtype: 'fieldset',
      flex: 1,
      margin: '0 5 0 0',
      items: [{
        { xtype: 'textfield', name: 'email', fieldLabel: 'Email' },
        { xtype: 'textfield', name: 'name', fieldLabel: 'Nome' },
    }, {
      title: 'Agencies',
      xtype: 'fieldset',
      flex: 1,
      items: checkboxes
    }];
[...]

Everything works well for submitting a form. I get all the data and can save it in the database.

When the user clicks on the grid, the record is loaded into the form with the standard:

form.loadRecord(record);

The problem is that the checkboxes are not checked. Are there any naming conventions for checkbox elements so that Extjs can determine what to install? How to set up relationships so that the form understands what to check? Or should I do everything manually?

+5
source share
2 answers

In your form, you can do something like this:

{
   xtype: 'checkboxfield',
   name: 'test',                                
   boxLabel: 'Test',
   inputValue: 'true',
   uncheckedValue: 'false'
}
+3

, someCheckbox.setValue(true) someCheckbox.setValue(false)

0

All Articles