Reputation: 73
I have a form with two input fields 'test1' and 'test2' and one combo box. I want to validate this form, the input fields should be not emtpy. I use therefore the config ' allowBlank: false' and the controller method 'onFormValidityChanged'. This works fine.
Now I hide the input field 'test2' when I change the value in the combo box with the controller method 'onChangeCombo' dynamically. Also, I set config ' allowBlank: true' of input field 'test2'. But my form is not valid when the hidden input field 'test2' is empty.
How can I exclude the hidden input field from the validity check?
I use the ExtJS version 6.6.
Thank you for your hints, Thomas
View:
items : [{
xtype : ' formpanel',
trackResetOnLoad : true,
layout : {
type : 'vbox',
align : 'stretch'
},
items : [
{
xtype : ' textfield',
name : 'test1'
itemId : 'test1',
allowBlank : false,
fieldLabel : 'test1'
},
{
xtype : ' combobox',
name : 'combo',
itemId : 'combo',
store: myStore,
listeners : {
change : 'onChangeCombo'
}
},
{
xtype : ' textfield',
name : 'test2'
itemId : 'test2',
allowBlank : false,
fieldLabel : 'test2'
}],
listeners : {
validitychange : 'onFormValidityChanged'
}
}];
Controller:
onFormValidityChanged : function(form, valid) {
var win, button;
win = form.owner.up('window');
button = win.down('[xtype=button]');
button.setDisabled(!valid);
},
onChangeCombo : function(combobox) {
var win, test2;
win = combobox.up('window');
test2 = win.down('textfield[itemId=test2]');
test2.hide();
test2.allowBlank = true;
}
Upvotes: 0
Views: 1418
Reputation: 73
Norbeq's proposal
test2.disable()
get not provide a solution. I don't know why...
I did not follow the dh117's formBind suggestion. I solved this problem as follows:
test2 = win('textfield[itemId=test2]');
win.remove(test2);
Thank you for your hints, also for the further hints, Thomas
Upvotes: 0
Reputation: 3076
to turn off the validation, just disable this hidden input.
test2.disable();
I have a suggestion for You too:
use test2.setAllowBlank(true) instead of test2.allowBlank = true
don't use reference like win.down(etc.), check out the ViewController options with reference and lookup method
Upvotes: 1