PDA

View Full Version : validator in combobox not marking field invalid



shailykamboj
28 Feb 2012, 6:25 AM
Hello ,
I am using validator config for one of the combobox in my form and it has a save button bound to it too , so in case if validation fails 'Save' would be disabled. Problem is i am always gettign the validator executed but few of the times it doesnt mark the combobox as invalid and neither will provide the error message but Save will be disabled !
Here is the code -

{
xtype: 'combo',
id: 'dlh_field',
editable: false,
fieldLabel: "Field",
allowBlank:false,
queryMode:'local',
triggerAction: 'all',
lastQuery: '',
store: Ext.create('Ext.data.Store', {
fields: ['profile', 'field'],
data : []
}),
msgTarget:'under',
displayField: "field",
valueField: "field",
disabled : true,
validator:function(val){
console.log('in Field validator..'+val);
if(Ext.isEmpty(val)){
return IA.util.LocaleMgr.get('requiredErrorMsg');
}
else
return true;
}

Thanks

mitchellsimoens
28 Feb 2012, 8:17 AM
So when it hits the validator and returns the string, the field doesn't even have the red invalid lines? Have not see that.

shailykamboj
28 Feb 2012, 8:17 AM
no , there are no red lines also

shailykamboj
28 Feb 2012, 8:42 AM
re sending the code with more details -
code for the two combo boxes :
//Profile ( profile selection listener only works the first time! )
{
xtype: 'combo',
id: 'dlh_profile',
editable: false,
fieldLabel: "Profile",
queryMode:'local',
store: Ext.create('Ext.data.Store', {
fields: [ 'name'],
data : []
}),
displayField: "name",
valueField: "name",
msgTarget:'under',
validator:function(val){
if(Ext.isEmpty(val)){
return IA.util.LocaleMgr.get('requiredErrorMsg');
}
else
return true;
},
listeners:{
select: function(combo, records, opts){
var profile = records[0].data.name ;

Ext.getCmp('dlh_field').enable();
Ext.getCmp('dlh_field').store.clearFilter(false);
Ext.getCmp('dlh_field').store.filter('profile', profile);
this.parentPanel.setDirty(true);
}
}

},

//Field
{
xtype: 'combo',
id: 'dlh_field',
editable: false,
fieldLabel: "Field",
allowBlank:false,
queryMode:'local',
triggerAction: 'all',
lastQuery: '',
store: Ext.create('Ext.data.Store', {
fields: ['profile', 'field'],
data : []
}),
msgTarget:'under',
displayField: "field",
valueField: "field",
disabled : true,
validator:function(val){
if(Ext.isEmpty(val)){
return IA.util.LocaleMgr.get('requiredErrorMsg');
}
else
return true;
},
listeners:{
select: function(combo, records, opts){
this.parentPanel.setDirty(true);
}


}
}
***************
code for save method , i had to put this because initially the comboboxes doesnt have any value selected and validator on them will be triggered only when a change is detected , so in case user justs clicks on save then the validation should be re run .
save : function()
{
var validatnPass = true;

if(Ext.getCmp('dlh_profile').isValid()){
if(!Ext.getCmp('dlh_field').isValid())
validatnPass = false;
}
else
validatnPass = false;
if(validatnPass){
this.callParent(arguments);
}

}

Is user doesnt slect any value and clicks save , first validation for profile' combo box is done and once pass it moves to combo box 'field' . If validation on 'profile' fails i can see red lines with the message but if validation for 'field' combo box fails then 'Save' button is disabled but no red lines or error message is displayed !! I have to click on the combo box and then outside of it to get the message ! but since the validation (in save method) is failing there should be an error message shown .

tobiu
28 Feb 2012, 8:43 AM
why are you using


allowBlank:false


combined with an validator that checks for the same thing? without your validator, the field should already get marked red when the validation event triggers (keyup, blur, etc.).

i would try it without the config to check if there are differences. the custom validation should get applied first.

Tod
2 Mar 2012, 12:40 PM
I had a similar problem, and my msgTarget and anchor were not set correctly... would not hurt to double check your code

-Tod

shailykamboj
2 Mar 2012, 12:57 PM
Thanks Tod for replying to the thread :-)
Can you share the msgTarget and anchor details , as to what were they before and what change you did.

shailykamboj
2 Mar 2012, 12:59 PM
Thanks Tobiu for replying to the thread :-)
I removed the allowBlank : false , but still seeing the issue

Tod
2 Mar 2012, 1:20 PM
Thanks Tod for replying to the thread :-)
Can you share the msgTarget and anchor details , as to what were they before and what change you did.

My problem was rather silly, and it affected TextField, not a combobox, so most likely I'm not helping at all... I simply did not have values for the msgTarget and anchor when I thought I did (variables did not exist). Having both was important for me to see validation (msgTarget: 'under', and anchor: '-0'.