PDA

View Full Version : itemselector validation



jamesjara
19 May 2010, 10:01 AM
HI , i cant make work the validation in the itemselector
i have this configuration


items: [{
anchor:'100% 100%',
xtype: 'itemselector',
name: 'F',
imagePath: '".$ux_image_path."',
isFormField: true,
allowBlank:false,
multiselects: [{
width:218,
height: 160,
store: ".$store_doc." ,
//Texto relacionado al store
displayField: 'B',
//ID relacionado al store
valueField: 'A'
},{
style: 'background-color: #FFF',
width: 218,
height: 160,
store: new Ext.data.ArrayStore(),
//Texto relacionado al store
displayField: 'B',
//ID relacionado al store
valueField: 'A',
allowBlank:false
}]
}]

leonardb
28 Jun 2010, 12:54 PM
Ran into a similar problem and I just created an override for the validate method. I also prefer getting the selected values back as an array instead of a string. Below is the override I'm using for ItemSelector. Hope this helps.




// Change the retrun type to an Array instead of a comma-sep string
// and allow for validation with allowBlank and minSelections
Ext.override(Ext.ux.form.ItemSelector, {
getValue: function() {
var retVal = this.hiddenField.dom.value;
return (retVal != '' ) ? retVal.split(','):[];
}
,validate: function() {
var cnt = this.getValue().length;
if ('undefined' != this.toMultiselect.minSelections) {
if (cnt < this.toMultiselect.minSelections) {
this.toMultiselect.markInvalid(this.toMultiselect.minSelections + ' or more items must be selected');
return false;
}
}
if ('undefined' != this.toMultiselect.allowBlank && this.toMultiselect.allowBlank == false) {
if (cnt == 0) {
this.toMultiselect.markInvalid('At least 1 item must be selected');
return false;
}
}
this.toMultiselect.clearInvalid();
return true;
}
});