Regarding asp mvc3 client-side validation, is it possible to mix by default, from a string of unobtrusive style with a jquery validation plugin?
This is the form in the view:
@using (Html.BeginForm("", "", FormMethod.Post, new { id = "newRatingForm" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Rating</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Rate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Rate)
@Html.ValidationMessageFor(model => model.Rate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
Unobtusive works fine by default, using the usual attributes for checking properties of model properties. The goal is to replace the model.Rate bits in the form with [fyneworks] [1] jquery star rating plugin and use the jquery validation plugin only for this part of the form:
<span>Your Rating:</span>
<div id="ratingStars">
<input class="star {split:2}" type="radio" name="Rating" value="0.5"/>
<input class="star {split:2}" type="radio" name="Rating" value="1.0"/>
<input class="star {split:2}" type="radio" name="Rating" value="1.5"/>
<input class="star {split:2}" type="radio" name="Rating" value="2.0"/>
<input class="star {split:2}" type="radio" name="Rating" value="2.5"/>
<input class="star {split:2}" type="radio" name="Rating" value="3.0"/>
<input class="star {split:2}" type="radio" name="Rating" value="3.5"/>
<input class="star {split:2}" type="radio" name="Rating" value="4.0"/>
<input class="star {split:2}" type="radio" name="Rating" value="4.5"/>
<input class="star {split:2}" type="radio" name="Rating" value="5.0"/>
</div>
I captured the submit action for the form and converted the form values to Json to execute an ajax request with:
$("#newRatingForm").submit(function (event) {
event.preventDefault();
if ($(this).valid()) {
newRatingSubmit();
}
});
function newRatingSubmit() {
}
-, , , , .. "", ( firebug), . , mvc3.
jquery , , , :
$("#newRatingForm").validate({
meta: "validate",
errorLabelContainer: "#ErrorDiv",
wrapper: "div",
rules:
{
Rating: {
required: true
}
},
messages:
{
Rating: {
required: 'A Rating required.'
}
},
onfocusout: false,
onkeyup: false,
submitHandler: function (label) {
newRatingSubmit();
}
});
html, , jquery, , "asp.net mvc". , - 1 , , .