mcki0127
(Steve)
November 17, 2016, 9:20pm
1
I’m using this JS code from Yii2-Cookbook:
Html::submitButton(HTML::icon('ok') . ' Add', [
'id' => 'add_submit',
'method' => 'POST',
'class' => 'btn btn-default btn-xs',
'name' => 'add',
'value' => $staffLink->id,
]) ?>
<script>
$('#add_submit').on('beforeSubmit', function (e) {
if (!confirm("Everything is correct. Submit?")) {
return false;
}
return true;
});
</script>
I’m just trying to get this to work before I write my own function in place of the alert. I want this function to run before validation. I have tried both “beforeSubmit” and “beforeValidate”, but neither one works. It goes straight to validation. What am I missing?
tri
(tri - Tommy Riboe)
November 18, 2016, 12:11am
2
I’m using this JS code from Yii2-Cookbook:
Html::submitButton(HTML::icon('ok') . ' Add', [
'id' => 'add_submit',
'method' => 'POST',
'class' => 'btn btn-default btn-xs',
'name' => 'add',
'value' => $staffLink->id,
]) ?>
<script>
$('#add_submit').on('beforeSubmit', function (e) {
if (!confirm("Everything is correct. Submit?")) {
return false;
}
return true;
});
</script>
I’m just trying to get this to work before I write my own function in place of the alert. I want this function to run before validation. I have tried both “beforeSubmit” and “beforeValidate”, but neither one works. It goes straight to validation. What am I missing?
I tried this
$this->registerJs(<<<'EOD'
$('#contact-form').on('beforeValidate', function (e) {
if (!confirm("Everything is correct. Submit?")) {
return false;
}
return true;
});
EOD
)
Resulting code added to page
<script type="text/javascript">jQuery(document).ready(function () {
$('#contact-form').on('beforeValidate', function (e) {
if (!confirm("Everything is correct. Submit?")) {
return false;
}
return true;
});
mcki0127
(Steve)
November 18, 2016, 2:04am
3
It works. I guess I need to learn more about registering assets. Thanks for your help.