I have this link in twig :
<a href="{{ path('relation-delete', {'id': c.getCustomerId}) }}"
onclick="return confirm('{% trans %}relation.delete{% endtrans %}');"
class="tip" data-original-title="Verwijder klant {{ c.getCustomerName }}">
The HTML in the source :
<a href="/app_dev.php/projects/delete/1" class="tip"
data-original-title="Verwijder project Lantaarn plaatsen"
onclick="return confirm('Verwijderen');">
<button class="btn btn-danger"><i class="fa fa-times fa-fw"></i></button></a>`
the onlick confirm cancel button doesn't cancel the action but just keeps going. Somebody knows what's wrong with this return confirm ?
You can validade the confirm box outside of html element, in a function and, call this function on 'onclick' event. Like this:
<a href="somePage" onclick="return myFunction()">My link</a>
function myFunction() {
if (confirm("Confirm message")) {
// do stuff
} else {
return false;
}
}
Adding event.preventDefault();
fixed it.
Here is an example:
console.log('Validating...');
function confirm_delete(){
var txt;
var r = confirm("Are you sure you want to delete?");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
event.preventDefault();
}
console.log(txt);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With