PDA

View Full Version : Allow blank field conditionally



Sejal
9 Feb 2010, 2:10 AM
Hi,

I have an issue, i want to make one numberfield mandatory but when some condition is true and initially it is not mandatory.

I have used markInvalid function so initally it is marked invalid but if i click on submit button that markInvalid thing disappears still that mandatory condition is true.

Thanks & regards,
sejal

tobiu
9 Feb 2010, 3:41 AM
here a short example, where the user has to enter a phoneNumber OR a mobileNumber. One of them is needed.



fE.phone = bT.form.NumberFieldZeroes({
allowLeadingZeroes : true
,readOnly : readOnly
,fieldLabel : 'Phone'
,name : 'phoneNumber'
,minLength : 7
,maxLength : 25
,disabled : disabled
,validator: function(value) {
if(value.length > 1 || fE.mobile.getValue().length > 1){
return true;
} else {
return 'You have to enter the phone- or the mobile number.';
}
}
});

fE.mobile = bT.form.NumberFieldZeroes({
allowLeadingZeroes : true
,readOnly : readOnly
,fieldLabel : 'Mobile'
,name : 'mobileNumber'
,minLength : 7
,maxLength : 25
,disabled : disabled
,listeners : {
blur : function(){
fE.phone.validate();
}
}
});


i hope this helps you, in which direction to go.

kind regards,
tobiu

Sejal
9 Feb 2010, 4:04 AM
Actually the condition which i need to put on number field its value is coming from different js file & number field is in another file so am checking its value in third file where i have condition & numberfield values both therefore i can't put validator in that file, so have to use some kind of functions like markInvalid or something else.. need help

tobiu
9 Feb 2010, 4:19 AM
then you have to call your functions in the form with a listener onBeforeSubmit and return false, if it failed so that the form won't submit.

kind regards,
tobiu