multiple submit buttons and confirmation dialogue on one of them

Notice: This thread is very old.
richard
Member | 60
+
0
-

Can I somehow add confirmation dialogue on one of the submit buttons in form?
It should popup after form validation and stop the form submit if false.

Thanks.

HosipLan
Moderator | 4668
+
0
-

That is a client side problem, isn't it? You can define in form definition

$input->controlPrototype
	->onsubmit = "return confirm('ORLY?');";

Or better, you can put it where it belongs, but you would have to render form manualy.

...
<tr><td>{input onsubmit => "return confirm('ORLY?');"}</td></tr>
...
richard
Member | 60
+
0
-

Hi,
adding onSubmit attribute to a submit button does not do anything, I believe this works only on form tag – but then it will be executed by any submit button in the form.

Thanks

richard
Member | 60
+
0
-

OK. This works a bit:

<?php
$form->addSubmit('submit1')->controlPrototype->onClick("window.check = false;");
$form->addSubmit('submit2')->controlPrototype->onClick("window.check = true;");
<script>
    Nette.addEvent(document.getElementById('frm-form), 'submit', function() {
        if(window.check) {
            if(!confirm("Sure?")) {
                return false;
            }
        }
});
</script>

But how to do that only if form validation is OK?
?>

Last edited by richard (2011-09-26 17:30)

HosipLan
Moderator | 4668
+
0
-

If you wanna add an event on form, you can

$form->elementPrototype
	->onsubmit = "if(window.check) {return confirm('ORLY?');}";

But there is already an event added to form using Unobtrusive JavaScript, so I'm not sure how it will behave.