I am using jquery validation & bootstrap. In views that i only have one form and I dont have to init the validator on the form. I have the input and the validation message span under the input. Styling is great. Red messages etc.
However, when i have 2 forms in a view I need to create a validator object myself. However when I create it and validation messages get displayed they don't have the same color/style.
How can init a validator with the same settings?
In jquery.validate.unobtrusive I found the following
options: { // options structure passed to jQuery Validate's validate() method
errorClass: defaultOptions.errorClass || "input-validation-error",
errorElement: defaultOptions.errorElement || "span",
errorPlacement: function () {
onError.apply(form, arguments);
execInContext("errorPlacement", arguments);
},
invalidHandler: function () {
onErrors.apply(form, arguments);
execInContext("invalidHandler", arguments);
},
messages: {},
rules: {},
success: function () {
onSuccess.apply(form, arguments);
execInContext("success", arguments);
}
},
So I am assuming I need those settings. But how can i invoke functions defined in that JavaScript file (e.g. onError
, onSuccess
)
1 Textbox: I dont have to call validate() or anything
@Html.TextBox("locationDate", "", new { @class = "dateInputMMYY form-control", @placeholder = "Move Date" })
@Html.ValidationMessage("locationDate")
2 TextBox: I invoke .validate() on the form:
@Html.TextBox("end", "", new { @class = "dateInput form-control search", @placeholder = "End Date" })
@Html.ValidationMessage("end")