2
votes

I have a simple ExtJS 4 (xtype form) inside a window. It has two fields and a save button. One of the fields is a string. That works fine. If it's blank, getValues() gives me the field blank. If it's set, I get the value. However, the check box is different. If it's checked, I get the value of '1'. HOWEVER, if I un-check the box (or do not check it), I get no value - the field is not listed in the result of getValues()! WHY??

items: [
                    {
                        xtype: 'checkbox',
                        name : 'insuranceVerified',
                        fieldLabel: 'insuranceVerified',
                        inputValue:'1',
                        value:'1'  //does not make a difference
                    },
                    {
                        xtype: 'textfield',
                        name : 'ru',
                        fieldLabel: 'ru'
                    }
]

I am catching the save button click event and calling this function in my controller:

updateEncounter: function(button) {
        console.log('clicked the Save button');
        var win    = button.up('window'),
            form   = win.down('form'),
            record = form.getRecord(),
            values = form.getValues();

// values properly shows the ru field on the form, but only shows insuranceVerified if it's checked - is not in values if it's unchecked... ??!

            debugger;
        record.set(values);
        this.getEncountersStore().sync();
        win.close();
    }

I just figured out something else, though it's not a complete answer for me: If I change the code above so it get's the form (I assume from the form panel):

 form   = win.down('form').getForm(),   // instead of win.down('form')

Then, use getFieldValues() on that new object instead of the getValues(), I now have the check box value even if it's un-checked.

values = form.getFieldValues();  // instead of getValues()

HOWEVER, the value I get back is 'false' (or true), not '0' or '1' like I specified with inputValue:'1'.

Also, I even tried setting a 'value' for the field '1', no difference whether I do that or not for getValues or getFieldValues().

3

3 Answers

0
votes

Submit an HTML form with empty checkboxes

What do you expect to receive if the checkbox isn't selected? You specified the value being sent if it is checked..

Here another solution: How come checkbox state is not always passed along to PHP script?

9
votes

This works for me. Hope to help with

{
   xtype: 'checkbox',
   boxLabel: modelFields[i].label,
   name: modelFields[i].name,
   //magic!
   inputValue: 1,
   uncheckedValue: 0
}
-1
votes

you can use

var answer1IsCorrect = Ext.getCmp('Answer1RadioButton').checked ? 1 : 0;

insted of true or false