formapro / JsFormValidatorBundle

The Javascript validation for Symfony 2, 3 and 4 forms
MIT License
128 stars 56 forks source link

Function for custom event doesn't work #147

Open isabelle112 opened 6 years ago

isabelle112 commented 6 years ago

Hi,

I am using the bundle for validating my symfony form. Everything works fine but now I need to validate at a custom event. I've tried to use the code from the readme file number 12, but I get the error, that

$('form').find('input[type=text], textarea') .blur(function(){ // Run validation for this field $(this).jsFormValidator('validate'); }).focus(function() { // Reset markers when focus on a field $(this).removeClass('error'); $(this).removeClass('ready'); }).jsFormValidator({'showErrors': function(errors){if (errors.length) { $(this).removeClass('ready'); $(this).addClass('error'); } else { $(this).removeClass('error'); $(this).addClass('ready'); }} }); this part of the code "is not a function". if I remove the last part from jsFormValidator({... I don't get an error.

Could you please help me, where the issue is?

Thanks!

zinoviosDev commented 6 years ago

Hi, I'm fighting with the same problem. Did you find some workarounds since your post ?

On my side, I'm observing that jsFormValidator function is defined in this little code: if(window.jQuery) { (function($) { $.fn.jsFormValidator = function(method) { if (!method) { return FpJsFormValidator.customizeMethods.get.apply($.makeArray(this), arguments); } else if (typeof method === 'object') { return $(FpJsFormValidator.customizeMethods.init.apply($.makeArray(this), arguments)); } else if (FpJsFormValidator.customizeMethods[method]) { return FpJsFormValidator.customizeMethods[method].apply($.makeArray(this), Array.prototype.slice.call(arguments, 1)); } else { $.error('Method ' + method + ' does not exist'); return this; } }; })(jQuery); } I've just copied the definition of the function in my js code just before doing treatment on customized events with $('form').find('input[type=text], textarea') .blur(function(){ // Run validation for this field $(this).jsFormValidator('validate') and that worked for one form but not the other one (I have 2 modal forms in my page). Maybe that could help in your case.

isabelle112 commented 6 years ago

Hey Marc, thanks for your message!

I did the same workaround like you. I've copied the JS Code straight in front of my validation code and now it's working for me. Unfortunately I ran into another issue :/ i have a 5 steps form and when I click on the back button it routes forward:/

I think someone posted an issue with a problem with 2 forms on the same page - maybe search for it could help you 😊.

Best regards, Isabelle

Outlook for Androidhttps://aka.ms/ghei36 herunterladen

Von: Marc Gesendet: Donnerstag, 31. Mai, 00:03 Betreff: Re: [formapro/JsFormValidatorBundle] Function for custom event doesn't work (#147) An: formapro/JsFormValidatorBundle Cc: isabelle112, Author

Hi, I'm fighting with the same problem. Did you find some workarounds since your post ? On my side, I'm observing that jsFormValidator function is defined in this little code: if(window.jQuery) { (function($) { $.fn.jsFormValidator = function(method) { if (!method) { return FpJsFormValidator.customizeMethods.get.apply($.makeArray(this), arguments); } else if (typeof method === 'object') { return $(FpJsFormValidator.customizeMethods.init.apply($.makeArray(this), arguments)); } else if (FpJsFormValidator.customizeMethods[method]) { return FpJsFormValidator.customizeMethods[method].apply($.makeArray(this), Array.prototype.slice.call(arguments, 1)); } else { $.error('Method ' + method + ' does not exist'); return this; } }; })(jQuery); } I've just copied the definition of the function in my js code just before doing treatment on customized events with $('form').find('input[type=text], textarea') .blur(function(){ // Run validation for this field $(this).jsFormValidator('validate') and that worked for one form but not the other one (I have 2 modal forms in my page). Maybe that could help in your case. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/formapro/JsFormValidatorBundle/issues/147#issuecomment-393334547, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWokSXoJdbUH7wWvTK7u3cfxikTVKp0Jks5t3xcegaJpZM4Tbnz3.