a dropdown with focus and enter key pressed validate for form.
I have a form with elements that are validated by jquery (in the validator function as below) If I have a textbox, and I enable focus on it and press enter, I get all of Javascript validations.
$( document ).ready(function() {
var container = $('div.errors');
$("mydropdownId").focus(); //tried this , focus works, but enter key press check doesn't work
// validate the form when it is submitted
var validator = $("#coverageForm").validate({
invalidHandler: function() {
$('#form_error_notice').css('display', 'block');
$('.server_error_notice').css('display', 'none');
$('.errorsServer').css('display', 'none');
hintAgain();
},
submitHandler: function(){
DoDisable(); //changes couple of divs and does document.form.submit();
},
errorContainer: $("#coverageForm .errors"),
errorLabelContainer: $("ul", "#coverageForm .errors"),
wrapper: 'li',
meta: "validate"
});
// Control input in numeric form fields
$('input.numeric').numeric();
开发者_如何学Python // Initiate overlays
$('.boxy').boxy({modal: true});
});
I am new to jquery, anyone who could guide me towards the light? I don't want to change the validation that jquery provides. It is a stringe requirement from my "client"!
Thanks in advance!
The default behavior for a html form is that when you click enter the form is submitted. So that kicks JQuery.Validator off to validate the fields on the form.
So to get around this, you might have to capture the keydown or keypress events, get the enter key down, then move to the next field manually (call focus on the next control)
精彩评论