Reputation: 45
After I have clicked either 'Yes' or 'No' on the confirmation dialog the OnSuccessForm() function does not trigger. Any ideas on how to halt the onBeginForm() before continuing?
My MVC3 Form
@using (Ajax.BeginForm("Edit", @ViewContext.Controller.ValueProvider.GetValue("controller").RawValue, new AjaxOptions
{
UpdateTargetId = Model.Title.Replace(" ", "") + "Form",
InsertionMode = InsertionMode.Replace,
OnBegin = "onBeginForm",
OnSuccess = "OnSuccessForm",
OnFailure = "showFaliure"
}))
{
@Html.ValidationSummary(true)
@Html.RenderStandardEditor("Edit " + Model.Title)
}
Here is my JavaScript Sample Code
<script type="text/javascript">
var confirmation = false;
function onBeginForm(ajaxContext)
{
$.confirm({
'title': 'Confirmation',
'message': 'Confirm?',
'buttons': {
'Yes': {
'class': 'cyan',
'action': function ()
{
confirmation = true;
}
},
'No': {
'class': 'gray',
'action': function ()
{
confirmation = false;
}
}
}
});
}
function OnSuccessForm(ajaxContext)
{
if (confirmation == true)
{
//DO SOMETHING
}
}
function showFaliure(ajaxContext)
{
//THROW ERROR
}
</script>
Upvotes: 0
Views: 1782
Reputation: 9073
I believe you're using the onSuccess function incorrectly. That function will get called only after your data is posted successfully. So regardless of what's chosen in your confirmation box data will get posted either way, and then your confirmation box only determines if anythings done with this data after it's posted. Is this truly what you want?
As for why your onSuccessForm isn't being hit, all I can offer is ways to try debugging it. Is showFaliure getting called instead? Using the firebug console is data getting posted at all? If you comment out everything inside your onBeginForm function is onSuccessForm getting called then?
Upvotes: 1