PDA

View Full Version : form field validator triggers



stimpy
28 Jun 2012, 12:34 PM
I have a form combobox with an attached validator as shown below.
However the field's validator is firing even when other unrelated fields ( which have no validators) in the same form are set.
Other then change and blur ( which should only effect that field) when else are a fields validator's triggered?


xtype:'combobox',
validateOnBlur:false,
validateOnChange:false,
validator:function(){
console.log('alert');
}

scottmartin
28 Jun 2012, 12:55 PM
This happens when you load data into the form? Can you be more specific?

Scott.

stimpy
28 Jun 2012, 5:11 PM
Given three combo boxes with preset values and fields it happens on selecting a value from the first combo box , which has no validator.

So

<Combo box # 1 >

<Combo box # 2 >

<Combo box # 3 >

ComboBoxes 2 and 3 validators defined. Selecting value from #1 triggers the validators in #2 AND #3 even with validateOnBlur and validateOnChange set to false on #2 and #3.

stimpy
29 Jun 2012, 3:34 AM
After reading some more I looked again at the #1 combo box. It had allowBlank set to false.

Thinking perhaps that was a "validation step", I commented that out and tested again. The result is the same ,selecting a result from one combo box triggered the validators on two ,otherwise unrelated, combo boxes in the same form .

Why is this ? And how do I prevent it from happening ?

Is allowBlank additive with a validator?

stimpy
29 Jun 2012, 5:39 AM
In an effort to produce a test case

using registration.js from sencha examples

remove the form items - replacing with the items in the code block below

in fieldvaliditychange
add console.log('fieldvaliditychange fired') above the exsiting "this.update..." line

in fielderrorchange
add console.log('fielderrorchange fired') above the exsiting "this.update..." line

RESULTS ( the console)
- form load = Validator 1 fired
- click on combobox one, select nothing = fieldvaliditychange fired AND Validator 1 fired
- click on combobox one, select a value=fieldvaliditychange fired AND Validator 1 fired AND Validator 2 fired AND Validator 1 fired
Repeat either of the above actions a second time = no console messages

So is the example broken or did i mess something up or what ??
Side note:Why are fieldvaliditychange and fielderrorchange NOT camel cased ?


{
xtype:'combobox',
margin:5,
name:'test1',
emptyText:'combo 1 empty text',
store: new Ext.data.SimpleStore({
fields:['testValue1],[testDisplay1]
data:[["1","display1"],["2","display2"]]
}),
displayField:'testDisplay1',
valueField:'testValue1',
querymode:'local'
},
{
xtype:'combobox',
margin:5,
name:'test2',
emptyText:'combo 2 empty text',
store: new Ext.data.SimpleStore({
fields:['testValue2],[testDisplay2]
data:[["1","display21"],["2","display22"]]
}),
displayField:'testDisplay2',
valueField:'testValue2',
querymode:'local',
validator:function(){
console.log('validator 1 fired');
}
},
{
xtype:'combobox',
margin:5,
name:'test3',
emptyText:'combo 3 empty text',
store: new Ext.data.SimpleStore({
fields:['testValue3],[testDisplay3]
data:[["1","display31"],["2","display32"]]
}),
displayField:'testDisplay3',
valueField:'testValue3',
querymode:'local',
validator:function(){
console.log('validator 2 fired');
}
}

rhinos
1 Jul 2012, 6:51 PM
Have you found a solution to this problem?

I have having very much the same problem.

stimpy
2 Jul 2012, 4:47 AM
Not yet

I am trying to find the documentation of the event model .

I think something else is triggering the valid handler.

stimpy
2 Jul 2012, 7:06 AM
Thinking that I was somehow flagging the form dirty , I made up the following changes.

On the form panel added

id:'testFormPanel',

inside the validators

var box1 = Ext.getCmp('testFormPanel').getForm();
console.log('validator 1 fired'+' form getDirtyVal is '+box1.isDirty());
and

var box2 = Ext.getCmp('testFormPanel').getForm();
console.log('validator 2 fired'+' form getDirtyVal is '+box2.isDirty());

Now my results are:
- form load = Validator 1 fired form getDirtyVal is false
- click on combobox 'test1', select nothing = fieldvaliditychange fired AND Validator 1 fired form getDirtyVal is false
- click on combobox 'test1', select a value=fieldvaliditychange fired AND Validator 1 fired form getDirtyVal is true AND Validator 2 fired form getDirtyVal is true AND Validator 1 fired form getDirtyVal is true
Repeat either of the above actions a second time = no console messages

I think whats happening here is that updateError state is calling get errors on each field and I am GUESSING that this triggers the validator on each field. However this does not explain why validator 1 in called on page load or why it is called a second time or why nothing is called if i change the value in box 'test1' having initially set it set it the first time.

anyone have any ideas ? is there documentation on this somewhere that I am missing ?