error display with jquery validate, textbox and select
See original GitHub issueI’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:
But as soon as I touch the select, the error displays incorrectly, and the select opens (even though it has no errors);
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:
- Created 8 years ago
- Reactions:1
- Comments:12 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
I applied some CSS and it appears to be working now, but I don’t know if this can be improved or not:
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.