question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error display with jquery validate, textbox and select

See original GitHub issue

I’m seeing a strange issue with error display when there’s a select box on the page. I’m using materializecss 0.97.0 and jquery.validate in an asp.net mvc app.

If I don’t touch the select, everything displays fine on validation: capture

But as soon as I touch the select, the error displays incorrectly, and the select opens (even though it has no errors);

capture2

I don’t think there’s anything tricky in my code:

    <form id="testForm">
        <div class="input-field row">
            <input id="last_name" type="text" class="validate" required>
            <label class="" for="last_name">Last Name</label>
        </div>
        <div class="input-field row">
            <input id="first_name" type="text" class="validate" required>
            <label class="" for="first_name">First Name</label>
        </div>
        @Html.Partial("_LocationPartial")
        <input class="submit" type="submit" value="Submit">
    </form>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="~/Scripts/materialize/materialize.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script>
    $.validator.setDefaults({
        errorClass: 'invalid',
        errorPlacement: function (error, element) {
            element.next("label").attr("data-error", error.contents().text());
        }
    });
    $('select').material_select();
    $('form').validate();
</script>

But I’m obviously doing something dumb, because this seems to obvious a problem for someone not to have run across it already.

Any ideas?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
juanekscommented, May 30, 2016

I’m from Ecuador, my English is not so good. About your problem, you have to add the name attribute to the input to work!! input id=“first_name” name=“first_name” Saludos.

2reactions
ghostcommented, Sep 12, 2015

I applied some CSS and it appears to be working now, but I don’t know if this can be improved or not:

label:after {
    transition-property: all !important;
    font-size: 0.8rem;
    transform: none;
}
label:not(.active):after {
    transform: translateY(-140%);
}

Essentially, the error message is just transitioned back to where it should be when the textbox is triggered.

Another option would be to ‘force’ the “active” class on elements with errors, but I couldn’t quickly come up with a clean way to do this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery Validation show error message for only one specific ...
You have a element.attr('placeholder', error.text()) , which will simply change the placeholder attribute into the error message, but only ...
Read more >
Documentation - jQuery Validation Plugin
You need to place error messages in the DOM and show and hide them when appropriate. ... A single line of jQuery to...
Read more >
Easy Form Validation With jQuery - Code Tutsplus
Using a jQuery plugin to validate forms serves a lot of purposes. It gives you additional abilities like easily displaying custom error ......
Read more >
Bootstrap snippet. Highlight textbox instead of error message ...
Bootstrap snippets. Highlight textbox instead of error message using jquery validations using HTML, Javascript, jQuery, and CSS by Srinu Sirigiri.
Read more >
Guide to jQuery validate errorplacement - eduCBA
Suppose we want to display the error message in that input placeholder or field itself, so we can use the statement as an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found