0

I have read most of questions that have been answered about this issue but till now can't get it to work, for 2 days now, I have this form

<form id="mr_project_form" class="post" role="form">
    <label class="fre-field-title" for="fre-project-title">Your project title</label>
    <input class="input-item text-field" id="fre-project-title" type="text" name="post_title" placeholder="Add more than 15 characters"/>
    <!--Submit button-->
</form>

And i can apply the validator on the input element here,like this

$( "#mr_project_form" ).validate();

Then after an AJAX call an input injected by AJAX response,So the form would be something like this

<form id="mr_project_form" class="post" role="form">
    <label class="fre-field-title" for="fre-project-title">Your project title</label>
    <input class="input-item text-field" id="fre-project-title" type="text" name="post_title" placeholder="Add more than 15 characters"/>

    <!--Inserted input-->
    <input class="input-item text-field" id="inserted_input" type="text" name="inserted_input"/>
    <!--Submit button-->
</form>

And as mentioned in #22287410 and #18022224, I should add the rule after the element been added, so in the ajax success i added the rule like this

$.ajax({
  url: mr_ajax_url,
  type: "POST",
  data: dataString,
  success: function (response) {
    $("#" + insertLcation).html(response);
    $('#inserted_input').rules('add', { digit: true, });
  },
});

But it can't be validated, and i get this error on pageload

TypeError: t.validator.methods[a] is undefined; can't access its "call" property

TypeError: s is undefined; can't access its "form" property

Community
  • 1
  • 1
Makiomar
  • 106
  • 1
  • 9
  • what is `insertLcation` ? – ewwink Dec 11 '18 at 08:16
  • @ewwink This AJAX insert html into different places, so i created a function that accepts a location and then do ajax, and it works fine,but the problem is that the inserted fields can't be validated – Makiomar Dec 11 '18 at 08:20

1 Answers1

1

its digits with s, not digit.

$('#inserted_input').rules('add', { digits: true, });
ewwink
  • 18,382
  • 2
  • 44
  • 54