Reputation: 559
It looks like I'm stuck trying to find a good solution for my issue. We have an MVC 3 application and a form, which we validate using Data Annotations. On Email field I have a RemoteAttribute which checks, that Email is unque. The this I need to implement:
If Email is unique - everything is ok, we don' tneed to do anything.
If Email is not unque - we need to show a modal popup window with a yes\no choice. If user chooses "yes" - the field will be valid, if "no" - field is invalid and we need to show a popup message.
Unfortunatelly, I couldn't find any good solution for this
Small update: I don't want to validate the whole form: only the Email field. In this case, can't really understand how to use form.Validate from jQuery or ValidationSummary
Upvotes: 1
Views: 3584
Reputation: 492
Try this:
In your view create container for errors form ModelState:
<div id="errorPopUp" style="display:none">
@Html.ValidationSummary()
</div>
and in script section of your view:
$(document).ready(function () {
if(@:!ModelState.IsValid) {
$('#errorPopUp').dialog({
resizable: false,
width: 400,
modal: true,
autoOpen: true
});
}
}
}
Upvotes: 3
Reputation: 2794
You can use jquery validate to do this:
var frm = $('#formData');
frm.validate();
if (frm.valid()) {
// do nth or submit the form
}
else{
// Declare a dialog
var $dialog = $('#dialogdiv').dialog({
autoOpen: false,
modal: true
});
// Declare the yes/no options
....
}
Is this the thing you need?
Hope this help :)
Upvotes: 1