Pregunta

I have a save button that triggers a jquery prompt (click the save button, and then I prompt the user: "Are you sure you want to save updates?" The problem is that a user can click the prompt multiple times, causing the same data to save multiple times. How can I disable the prompt save button on the first click?

I am using knockout js. Here is the code in my viewmodel:

$.prompt("Are you sure you want to save? You will not be able to change your decision after it's been saved.", {
    title: "Save?",
    buttons: { "Save": true, "Cancel": false },
    submit: function (e, v, m, f) {
        if (v) {
            e.disabled = true;
            response = saveUpdates(LoanDetails);
        }
    }
    }
});
¿Fue útil?

Solución

You can disable the button after saving data for the first time. You can use different jquery selector for your button.

$('button[type=submit], input[type=submit]').attr('disabled',true);

Otros consejos

Try disabling the button itself when you do the save. Then the button wont be clickable and you wont get the prompt.

If you want to disable a button using jQuery, you should have a look at $('#elem').prop(property,value), which will allow you to do something like this...

$("input").prop("disabled",true);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top