Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

validation does not work when textbox value is programmatically set #52

Closed
channeladam opened this Issue Mar 7, 2011 · 3 comments

Comments

Projects
None yet
3 participants

Given a form with two textboxes (as a simple example of the issue)
When the first textbox has a class of 'required'
And the second textbox's value has been set programmatically
Then validation on the first textbox should happen
BUT IT DOES NOT!

Below is a sample HTML to illustrate the issue. Follow the instructions at the bottom to manually reproduce the issue.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.js"></script>

<script type="text/javascript">
    $(document).ready(function () {

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

        $('#text2').val('2');  // this causes validation of #text1 not to happen

        $('#text2').focus();

    });
</script>

<form id="myForm" action="">

    <label for="text1">Text 1 *</label>
    <input id="text1" name="text1" class="required" type="text" />
    <br/>

    <label for="text2">Text 2</label>
    <input id="text2" name="text2" type="text" />
    <br/>

</form>

<h1>Instructions</h1>
<para>
    Because the JavaScript programmatically sets the value of Text 2, jquery.validate doesn't properly validate the required field Text 1.
    <br/><br/>
    (1) Focus should automatically be on Text 2<br/>
    (2) Press Shift-Tab to put focus on Text 1 (or use the mouse)<br/>
    (3) Type 'a' and then press Tab to put focus on Text 2<br/>
    (4) Press Shift-Tab to put focus back on Text 1 (or use the mouse)<br/>
    (5) Press Backspace to clear out the value in Text 1<br/>
    (6) At this point, the validation message should occur, but it doesn't!<br/>
    <br/>
    Comment out the JavaScript line "$('#text2').val('2');" and try the test again... validation will work.
</para>

Is this a duplicate of / related to Issue #14?

Contributor

mlynch commented Apr 24, 2012

Possibly fixed by #396

Contributor

mlynch commented Apr 25, 2012

Duplicate of #244

@mlynch mlynch closed this Apr 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment