- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<?php Pjax::begin(['id' => 'members']) ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
// 'filterModel' => $searchModel,
'columns' => [
['header'=>'Remove Member',
'value'=> function($data)
{
return Html::a(Yii::t('app', ' {modelClass}', [
'modelClass' =>'',
]), ['members/stl_remove','id'=>$data->id],
['class' => 'btn btn-link fa fa-times fa-2x pop']
);
},
'format' => 'raw'
],
['class' => 'yii\grid\ActionColumn','template'=>'{update}'],
],
]); ?>
<?php Pjax::end() ?>
当我点击“删除成员”链接时,会弹出一个模式窗口(delete.php)
<?php Pjax::begin(['id' => 'delete_members']) ?>
<?php $form = ActiveForm::begin(['options' => ['data-pjax' => true ]]); ?>
<div class="row">
<div class="col-md-5">
<?php echo $form->field($model, 'remarks')->dropDownList(['death' => 'Death',
'marriage' => 'Marriage', 'house_shift' => 'House Shift'],['prompt'=>'Select'])
->label("Reason For Removal"); ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Remove') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
<?php yii\widgets\Pjax::end() ?>
现在这些是我的 Controller 代码[代码]
public function actionStl_remove($id,$ajax=0)
{
$model = $this->findModel($id);
$model_delete = new Members();
$model->scenario = "remove";
if ($model_delete->load(Yii::$app->request->post()))
{
$model->remarks = $model_delete->remarks;
$model->status = 1;
$model->save();
// $model = new Members();
// return $this->redirect(['index']);
}
else
{
return $this->renderAjax('delete', [
'model' => $model_delete,
'id' => $id,
]);
}
}
我无法将数据加载到 gridview 中。我点击链接模式弹出窗口,然后提交,然后进入索引页面,页面重新加载
最佳答案
这就是我让它工作的方式。在 delete.php 中,我做了以下更改。
<?php $form = ActiveForm::begin([
'options' => ['data-pjax' => true,
'id'=> 'dynamic-form111',
// 'validationUrl' => 'validation-rul'
]]); ?>
<div class="row">
<div class="col-md-5">
<?php echo $form->field($model, 'remarks')->dropDownList(['death' => 'Death',
'marriage' => 'Marriage', 'house_shift' => 'House Shift'],['prompt'=>'Select'])
->label("Reason For Removal"); ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Remove') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
基本上我给了一个来自dynamic-form111
的id。然后在 index.php 以及 pjax 中的 gridview 中我添加了以下代码
<?php
$this->registerJs(
'jQuery(document).ready(function($){
$(document).ready(function () {
$("body").on("beforeSubmit", "form#dynamic-form111", function () {
var form = $(this);
// return false if form still have some validation errors
if (form.find(".has-error").length)
{
return false;
}
// submit form
$.ajax({
url : form.attr("action"),
type : "post",
data : form.serialize(),
success: function (response)
{
$("#ajaxModal").modal("toggle");
$.pjax.reload({container:"#countries"}); //for pjax update
},
error : function ()
{
console.log("internal server error");
}
});
return false;
});
});
});'
);
?>
通过ajax检查delete.php是否已成功提交,如果是,则使用pjax重新加载gridview并关闭模式。
关于ActiveForm 和 GridView 上的 Yii2 Pjax [让它工作起来],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34651018/
我无法在新创建的按钮上获得新创建的窗体上的控件计数,我创建了 5 个控件,但只显示了一个。如果我无法获得控件总数,那么我也无法获得控件类型、名称等。 private void button2_Clic
这是我的模特联系人, public function rules() { return [ [['fname', 'status','mobile',], 'required'
我有一个 Jquery 函数来激活和停用基于当前表单的表单。当我单击提交按钮时,如果我将它设置为 ID,我可以在页面加载时获取事件表单的值,但第二个表单没有任何内容。当我将它设置为类时,它似乎根本没有
本文实例讲述了Yii2创建表单(ActiveForm)的方法。分享给大家供大家参考,具体如下: 由于表单涉及到一些验证方面的信息,属性设置又比较多、比较复杂,所以哪里有什么不正确的地方请留言指点
我知道这是糟糕的设计,但我一直将对 GUI 表单类的控制权转移到 C# 程序中的其他类。 这已经工作很长时间了,使用: var form = Form.ActiveForm as Form1; 随着我
在一个好的项目中,它应该是这样的: jQuery(document).ready(function() { jQuery('#form-signup')
在Yii 1.X版本中,我们可以在CActiveForm类的clientOptions属性中使用afterValidate,请告诉我正确的实现方法Yii2 中也是如此 最佳答案 我刚刚看到这些变化。我
下面的 View 由ajax渲染并从 Controller 返回到JS,JS将 View 放入正确的容器中: $page = $this->renderAjax("view", [
我正在创建一个表单 View ,我想使用官方的选项卡小部件组织具有选项卡结构的表单字段。 是否可以使用包含事件表单字段的 div 元素的 id(或类)来初始化 Tabs 小部件? 最佳答案 如何管理它
我想使用 yii2 ActiveForm 创建表单。这是我的代码: [ 'class' => 'form-inline' ] ]); ?> Email
根据official tutorial Yii2的。我为报名表创建了一个 View : field($model, 'name')->label('Your Name')
在我的mysql数据库中存在一个articleID作为AI PK和一个articleNumber,用户可以编辑。 问题: 在yii2 ActiveForm中,我想让用户输入articleNumber,
在我使用的旧 Yii 中 labelEx($model,'text').'* '); ?> 我应该在 yii2 中使用什么来标记? 最佳答案 Yii2 的方式如下: field($model,
我正在使用 Yii2 和 ActiveForm。 通常,如果 ActiveForm 中的任何输入已被使用,输入的名称应与 ActiveRecord 属性相同,即数据库中相关表的列名称。 出于某种原因我
我正在使用 Yii 开发一个项目。 我需要在网站的许多页面上使用 jquery ui。因此,我在网站布局中添加了 jquery 核心库和 jquery ui 库,以便在所有页面上访问它们。 但是它会在
在我的表单模型中,我有一个以这种方式定义的字段的自定义验证函数 class SignupForm extends Model { public function rules() {
我如何使用符合这些要求的 ActiveForm? 用ajax提交表单。 使用ajax提交之前:检查是否有错误退出。 提交后:如果服务器响应保存失败结果,则显示字段输入下的字段错误。 最佳答案 这是你的
在我的下拉列表中,当我选择百分比时,“vendor 佣金”(下一个字段)的标签应为“百分比”。当我选择金额时,标签应为“金额” if($model->userType!="ADMIN" && $mod
如何自动禁用 Yii(验证 onblur)ajax 验证?我只想在按下提交按钮后进行验证。 最佳答案 您想使用 enableAjaxValidation验证您的表单,同时不想在每个 blur 上触发
在同一个表单上有多个模型我不想在两个模型上保存数据,但我只想在 View 文件上显示一个变量 我有两张 table 组织者 和事件Organiser 将登录并创建事件现在两个表中有几个共同的字段所以当
我是一名优秀的程序员,十分优秀!