我想監視更改的表單並在離開頁面之前提醒用戶。所以我用一個骯髒的形式插件found here骯髒的表單無法正常工作
這是我試圖
代碼形式
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\Countries;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model app\models\Organizations */
/* @var $form yii\widgets\ActiveForm */
?>
<link rel="stylesheet" href="<?php echo Yii::$app->request->baseUrl;?>/css/userHome.css">
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery.dirtyforms/2.0.0-beta00005/jquery.dirtyforms.min.js"></script>
<div class="organizations-form">
<h2>Update Billing Address</h2><br>
<div class="col-md-10 col-md-offset2">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'bill_name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'bill_address')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'bill_country_id')->dropDownList(ArrayHelper::map(Countries::find()
->all(), 'id', 'name'),['prompt'=>'Choose a Country'])->label('Select Country') ?>
<?= $form->field($model, 'bill_state')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'bill_city')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'bill_postal')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'bill_mobile')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-primary' : 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
腳本中使用
<script>
jQuery(document).ready(function($){
// Enable on all forms
$('form').dirtyForms();
});
</script>
現在,如果我嘗試去其他網頁或鏈接沒有保存我彈出meassege。但是,當我嘗試提交消息,即使彈出窗口出現。 這是爲什麼呢?
請提供相關的html嗎? –
發佈呈現的HTML –
我通過標題窗體給出的代碼是具有窗體的視圖,它是呈現的頁面。它的一個yii2代碼 – Bloodhound