[jQuery] Re: [validate] dynamic message
Hi, I am trying to validate an optional field but it is validated every time either it is included or not on the form.Please help me that how can i validate optional fields using jQuery validator. Regards, Himanshu Singh On Jan 26, 3:18 pm, Jörn Zaefferer joern.zaeffe...@googlemail.com wrote: Try this workaround - updatevalidator.settings.messages[element.name] with the appropiate value inside your validation method: $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ this.settings.messages[element.name] = some dynamic message + dynamicValue; return false; } }, whatever)); On Sun, Jan 25, 2009 at 10:33 PM, thomas thomas.bik...@gmail.com wrote: Thanks Jörn, but is there a way to change param dynamically during JS runtime? As example in your custom-methods-demo.html I'd like 11 to be a function of value ... math: {equal: 11} In my barcoding example, I'd like not only tell user that barcode number is wrong, but also what the check digit should be for what he has typed. In order to pass it into template Entered number is wrong the check digit must be {0} I need to be able to alter param somehow ... Regards, Thomas On Jan 25, 2:29 pm, Jörn Zaefferer joern.zaeffe...@googlemail.com wrote: You can use $.format to create dynamic messages, but that works only when the dynamic part is specified as a parameter. $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ return false;} }, $.format('dynamic message goes here with param {0}')); Jörn On Sat, Jan 24, 2009 at 10:54 AM, thomas thomas.bik...@gmail.com wrote: Hello group! Very happy to have deployed validation plugin ( I mostly need to check validity of EAN/UPC numbers for barcode generation). You can see it in action here:http://www.barcoderobot.com/ean-13.html The question I am struggling with though is howto return a 'dynamically generated' message. Say, '13 digits are required, you have XX'? $.validator.addMethod(dynamic_check, function(value) { if(_value is incorrect_){ return False;} }, 'dynamic message goes here');
[jQuery] Re: [validate] dynamic message
Jörn, many thanks - this has worked wonderfully! The only remaining question I have is as follows: messages generated by specified validation methods clear automatically after the form field gets updated: so in the chain of required,digits,minlength,maxlength each message comes and goes as needed. This seems not be the case with the solution you have suggested. Once specified the this.settings.messages [element.name] sticks and does not clear. How to reset it back to nothing and re-launch validation chain when the form value changes? With kind regards, Thomas On Jan 26, 11:18 am, Jörn Zaefferer joern.zaeffe...@googlemail.com wrote: Try this workaround - update validator.settings.messages[element.name] with the appropiate value inside your validation method: $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ this.settings.messages[element.name] = some dynamic message + dynamicValue; return false; } }, whatever)); On Sun, Jan 25, 2009 at 10:33 PM, thomas thomas.bik...@gmail.com wrote: Thanks Jörn, but is there a way to change param dynamically during JS runtime? As example in your custom-methods-demo.html I'd like 11 to be a function of value ... math: {equal: 11} In my barcoding example, I'd like not only tell user that barcode number is wrong, but also what the check digit should be for what he has typed. In order to pass it into template Entered number is wrong the check digit must be {0} I need to be able to alter param somehow ... Regards, Thomas On Jan 25, 2:29 pm, Jörn Zaefferer joern.zaeffe...@googlemail.com wrote: You can use $.format to create dynamic messages, but that works only when the dynamic part is specified as a parameter. $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ return false;} }, $.format('dynamic message goes here with param {0}')); Jörn On Sat, Jan 24, 2009 at 10:54 AM, thomas thomas.bik...@gmail.com wrote: Hello group! Very happy to have deployed validation plugin ( I mostly need to check validity of EAN/UPC numbers for barcode generation). You can see it in action here:http://www.barcoderobot.com/ean-13.html The question I am struggling with though is howto return a 'dynamically generated' message. Say, '13 digits are required, you have XX'? $.validator.addMethod(dynamic_check, function(value) { if(_value is incorrect_){ return False;} }, 'dynamic message goes here');
[jQuery] Re: [validate] dynamic message
Ah, good question. Try this: $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ this.settings.messages[element.name].dynamic_check = some dynamic message + dynamicValue; return false; } }, whatever)); That sets the new message only for this method. Jörn On Fri, Jan 30, 2009 at 12:09 PM, thomas thomas.bik...@gmail.com wrote: Jörn, many thanks - this has worked wonderfully! The only remaining question I have is as follows: messages generated by specified validation methods clear automatically after the form field gets updated: so in the chain of required,digits,minlength,maxlength each message comes and goes as needed. This seems not be the case with the solution you have suggested. Once specified the this.settings.messages [element.name] sticks and does not clear. How to reset it back to nothing and re-launch validation chain when the form value changes? With kind regards, Thomas On Jan 26, 11:18 am, Jörn Zaefferer joern.zaeffe...@googlemail.com wrote: Try this workaround - update validator.settings.messages[element.name] with the appropiate value inside your validation method: $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ this.settings.messages[element.name] = some dynamic message + dynamicValue; return false; } }, whatever)); On Sun, Jan 25, 2009 at 10:33 PM, thomas thomas.bik...@gmail.com wrote: Thanks Jörn, but is there a way to change param dynamically during JS runtime? As example in your custom-methods-demo.html I'd like 11 to be a function of value ... math: {equal: 11} In my barcoding example, I'd like not only tell user that barcode number is wrong, but also what the check digit should be for what he has typed. In order to pass it into template Entered number is wrong the check digit must be {0} I need to be able to alter param somehow ... Regards, Thomas On Jan 25, 2:29 pm, Jörn Zaefferer joern.zaeffe...@googlemail.com wrote: You can use $.format to create dynamic messages, but that works only when the dynamic part is specified as a parameter. $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ return false;} }, $.format('dynamic message goes here with param {0}')); Jörn On Sat, Jan 24, 2009 at 10:54 AM, thomas thomas.bik...@gmail.com wrote: Hello group! Very happy to have deployed validation plugin ( I mostly need to check validity of EAN/UPC numbers for barcode generation). You can see it in action here:http://www.barcoderobot.com/ean-13.html The question I am struggling with though is howto return a 'dynamically generated' message. Say, '13 digits are required, you have XX'? $.validator.addMethod(dynamic_check, function(value) { if(_value is incorrect_){ return False;} }, 'dynamic message goes here');
[jQuery] Re: [validate] dynamic message
Try this workaround - update validator.settings.messages[element.name] with the appropiate value inside your validation method: $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ this.settings.messages[element.name] = some dynamic message + dynamicValue; return false; } }, whatever)); On Sun, Jan 25, 2009 at 10:33 PM, thomas thomas.bik...@gmail.com wrote: Thanks Jörn, but is there a way to change param dynamically during JS runtime? As example in your custom-methods-demo.html I'd like 11 to be a function of value ... math: {equal: 11} In my barcoding example, I'd like not only tell user that barcode number is wrong, but also what the check digit should be for what he has typed. In order to pass it into template Entered number is wrong the check digit must be {0} I need to be able to alter param somehow ... Regards, Thomas On Jan 25, 2:29 pm, Jörn Zaefferer joern.zaeffe...@googlemail.com wrote: You can use $.format to create dynamic messages, but that works only when the dynamic part is specified as a parameter. $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ return false;} }, $.format('dynamic message goes here with param {0}')); Jörn On Sat, Jan 24, 2009 at 10:54 AM, thomas thomas.bik...@gmail.com wrote: Hello group! Very happy to have deployed validation plugin ( I mostly need to check validity of EAN/UPC numbers for barcode generation). You can see it in action here:http://www.barcoderobot.com/ean-13.html The question I am struggling with though is howto return a 'dynamically generated' message. Say, '13 digits are required, you have XX'? $.validator.addMethod(dynamic_check, function(value) { if(_value is incorrect_){ return False;} }, 'dynamic message goes here');
[jQuery] Re: [validate] dynamic message
You can use $.format to create dynamic messages, but that works only when the dynamic part is specified as a parameter. $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ return false;} }, $.format('dynamic message goes here with param {0}')); Jörn On Sat, Jan 24, 2009 at 10:54 AM, thomas thomas.bik...@gmail.com wrote: Hello group! Very happy to have deployed validation plugin ( I mostly need to check validity of EAN/UPC numbers for barcode generation). You can see it in action here: http://www.barcoderobot.com/ean-13.html The question I am struggling with though is howto return a 'dynamically generated' message. Say, '13 digits are required, you have XX'? $.validator.addMethod(dynamic_check, function(value) { if(_value is incorrect_){ return False;} }, 'dynamic message goes here');
[jQuery] Re: [validate] dynamic message
Thanks Jörn, but is there a way to change param dynamically during JS runtime? As example in your custom-methods-demo.html I'd like 11 to be a function of value ... math: {equal: 11} In my barcoding example, I'd like not only tell user that barcode number is wrong, but also what the check digit should be for what he has typed. In order to pass it into template Entered number is wrong the check digit must be {0} I need to be able to alter param somehow ... Regards, Thomas On Jan 25, 2:29 pm, Jörn Zaefferer joern.zaeffe...@googlemail.com wrote: You can use $.format to create dynamic messages, but that works only when the dynamic part is specified as a parameter. $.validator.addMethod(dynamic_check, function(value, element, param) { if(incorrect(value, param)){ return false;} }, $.format('dynamic message goes here with param {0}')); Jörn On Sat, Jan 24, 2009 at 10:54 AM, thomas thomas.bik...@gmail.com wrote: Hello group! Very happy to have deployed validation plugin ( I mostly need to check validity of EAN/UPC numbers for barcode generation). You can see it in action here:http://www.barcoderobot.com/ean-13.html The question I am struggling with though is howto return a 'dynamically generated' message. Say, '13 digits are required, you have XX'? $.validator.addMethod(dynamic_check, function(value) { if(_value is incorrect_){ return False;} }, 'dynamic message goes here');