PDA

View Full Version : checkbox and formbind



peturkirke
18 Mar 2013, 9:24 AM
When using formbind in ext js 3, i can setup my textfields like this:

items:[{
name:'Username',
allowBlank:false
},{
name:'Password',
inputType:'password',
allowBlank:false
}],

but how do i setup a checkbox, which i want to be checked, using formbind, something like allownotchecked: false ?

mitchellsimoens
20 Mar 2013, 1:05 PM
Something like this?


Ext.ns('Ext.ux.form');

Ext.ux.form.Checkbox = Ext.extend(Ext.form.Checkbox, {
blankText : 'This field is required',

getErrors : function() {
var errors = Ext.ux.form.Checkbox.superclass.getErrors.call(this);

if (this.allowBlank === false && !this.getValue()) {
errors.push(this.blankText);
}

return errors;
}
});

Ext.reg('ux-checkbox', Ext.ux.form.Checkbox);

Ext.onReady(function() {

new Ext.form.FormPanel({
renderTo : document.body,
title : 'Test',
monitorValid : true,
items : [
{
xtype : 'textfield',
fieldLabel : 'Test',
allowBlank : false
},
{
xtype : 'ux-checkbox',
fieldLabel : 'Test',
allowBlank : false
}
],
buttons : [
{
xtype : 'button',
text : 'Submit',
formBind : true
}
]
});

});

peturkirke
20 Mar 2013, 4:09 PM
hmm, i think so, in fact i only wanted to know the syntax in the item area for saying that the checkbox must be
checked, so i guess i can also use allowBlank for checkbox just like for textfields ? I will try it tomorrow, thanks for your help

mitchellsimoens
21 Mar 2013, 5:07 AM
allowBlank won't work on it's own, so if you look at my example I actually extended Combobox to handle it.

peturkirke
21 Mar 2013, 6:36 AM
ok ... thanks again