Answer the question
In order to leave comments, you need to log in
Why is this.init is not a function when running validation in a react app?
There is a react form, the validation of which goes through the jquery validation plugin. I validate in the following way:
let validator = $('form').validate({
errorClass: 'has-error',
errorElement:'label',
});
validator.form();
if ($('.has-error').length > 0) {
$('.has-error').each(function (index) {
$.validator().showErrors({prop:$(this).data('error')});
});
} else {
/*обрабатываем данные*/}
this.init is not a function
$.validator = function( options, form ) {
this.settings = $.extend( true, {}, $.validator.defaults, options );
this.currentForm = form;
this.init();
};
$.extend( $.validator, {
//some code
prototype: {
init: function() {
this.labelContainer = $( this.settings.errorLabelContainer );
this.errorContext = this.labelContainer.length && this.labelContainer || $( this.currentForm );
this.containers = $( this.settings.errorContainer ).add( this.settings.errorLabelContainer );
this.submitted = {};
this.valueCache = {};
this.pendingRequest = 0;
this.pending = {};
this.invalid = {};
this.reset();
//some code
Answer the question
In order to leave comments, you need to log in
The error was that $.validator() is essentially a constructor, and so an already created validator instance should have been used instead in the error line.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question