Код: Выделить всё
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'col1',
'col2',
[
'format'=>'raw',
'value'=>function($model){
$n='inledit'.$model->id;
$form=ActiveForm::begin(['id'=>$n, 'action'=>['update','id'=>$model->id], 'options' => ['name' => 'inleditfrm']]);
$f=Html::activeTextInput($model, 'col3', ['form'=>$n, 'id'=>'inp'.$n, 'style' => 'width: 300px;']);
$btn=Html::submitButton(Yii::t('app', 'Сохранить'), ['class' => 'btn btn-primary','form'=>$n]);
ActiveForm::end();
return $f.$btn;
}
],
],
]);?>
Код: Выделить всё
<?php
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
//return $this->redirect(['view', 'id' => $model->id]);
return Yii::$app->response->statusCode = 200;
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
?>
Код: Выделить всё
$('[name=inleditfrm]').on('beforeSubmit', function(e) {
var form = $(this);
var formData = form.serialize();
$.ajax({
url: form.attr("action"),
type: form.attr("method"),
data: formData,
success: function (data) {
$('input[form='+this.id+']').css({"color":"grey",});
}.bind(this),
error: function () {
alert("Something went wrong");
}
});
}).on('submit', function(e){
e.preventDefault();
});
//Model - Имя модели
$('[name="Model[col3]"]').on('change', function(e){
$(this).css({"color":"red",});
});