0

I'm using JQUERY validator plugin on my ASP.NET web forms with a master page. Obviously the FORM element is at master page. In one of the child form I have few divs with different input blocks. So I tried to initialise the validator like this

    $('#teambasic').validate({
        rules: {
            teamName: {
                required: true,
                minlength: 3
            }
        }
    });

    $('#extradetails').validate({
        rules: {
            domain: {
                required: true,
                minlength: 3
            }
        }
    });

Each of these divs are in different steps of the wizard and on clicking next button Im calling the valid function. But on calling the function it triggers an error

jquery.validate.min.js:4 Uncaught TypeError: Cannot read property 'element' of undefined
    at HTMLDivElement.<anonymous> (jquery.validate.min.js:4)
    at Function.each (jquery.min.js:2)
    at w.fn.init.each (jquery.min.js:2)
    at w.fn.init.valid (jquery.validate.min.js:4)
    at <anonymous>:1:32

On googling I found there could be a chance of this error if the inputs are outside the form tag. But in my case its all inside the FORM tag in master page. I verified its using jquery

$('input[name=teamName]').parents('form').length

which returned 1 since it has the parent form. I am not able to figure out where the trouble is

4
  • You must have name attribute on control to use this plugin. Are you missing name attribute ? Commented Jul 16, 2019 at 11:54
  • See this sample fiddle how to use name attribute to set rule. jsfiddle.net/740epqhb Commented Jul 16, 2019 at 12:00
  • @Shree Yea, I have name attribute in the control <input name='teamName'....... Commented Jul 16, 2019 at 12:22
  • You're not showing enough code to demonstrate the problem. WHERE are you attaching the .valid() method? Where is the rendered HTML markup? You cannot have nested form elements with this plugin. That is invalid HTML. You also absolutely cannot attach the .valid() method to a div, if that's what you did, hence the error message about an element. Commented Jul 16, 2019 at 14:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.