ajax - In a user's Edit Info form, how do I include the name of the field(s) and user's input value(s) in a response from the model -
on yii2 project, in user's edit info form (inside modal):
i'm figuring out fields changed using jquery .change()
method, , i'm grabbing value jquery's .val()
method.
however, want less javascript , more yii's framework.
i can see in yii debugger (after clicking ajax post request) yii smart enough know fields changed -- it's showing sql queries update
fields changed.
what need change in controller of action have yii include name of field changed -- including it's value -- in ajax response? (since goal update main view new values)
public function actionupdatestudentinfo($id) { $model = \app\models\studentsupportstudentinfo::findone($id); if ($model === null) { throw new notfoundhttpexception('the requested page not exist.'); } $model->scenario = true ? "update-email" : "update-studentid"; if ($model->load(yii::$app->request->post()) && $model->save()) { return $this->renderajax('_student_support_alert_success'); } return $this->renderajax("_edit_student_info",[ "model" => $model, ]); }
i'm returning static success view.
you can use $model->dirtyattributes
after load data $attrib => $value
pair array.
http://www.yiiframework.com/doc-2.0/yii-db-baseactiverecord.html#getdirtyattributes()-detail (this docs says:)
returns attribute values have been modified since loaded or saved recently.
the comparison of new , old values made identical values using ===.
public array getdirtyattributes ( $names = null )
(sorry formatting, sent mobile)
Comments
Post a Comment