This is a piece of my current model:
[Required(ErrorMessage = "First name is required!")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Email name is required!")]
[EmailAddress(ErrorMessage = "Invalid email address!")]
public string Email { get; set; }
Is it possible to show the ErrorMessage while typing and not when the "out of focus" of the input occurs? The view is auto-generated.
UPDATE This piece of code was provided by @vendettamit. It is working 50%. The problem is that I have more ErrorMeesages and they all pop out.
$(document).ready(function () {
var settngs = $('form').data('validator').settings;
settngs.onkeyup = function () {
$('form').valid();
};
settngs.onfocusout = false;
});
Get the validator object of unobtrusive jquery validation. Change the event that should trigger the validation.
$(document).ready(function () {
var $validatr = $('form').data('validator');
var settngs = $validatr.settings;
settngs.onkeyup = function (element, eventType) {
if (!$validatr.element(element))
{
$(this.currentForm).triggerHandler("invalid-form", [this]);
}
};
settngs.onfocusout = false;
});
Update -
It seems you have to manually trigger the validation for onkeyup. Updated the snippet.
Updated with trigger for single element validation.
Check out all validation options for more customization here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With