kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
557 stars 302 forks source link

Gridview shows the wrong format of data #1028

Closed thelaw29 closed 2 years ago

thelaw29 commented 2 years ago

Hello,

May I know is there a way to allow the validation in gridview to function as currently it still shows the wrong format of data when updating it. The first pic is to show that it allows the wrong format to be shown but I want to not allow it to be shown when it updates and should revert to its original value. The second picture is the code used for the validation.

image

image

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

kartik-v commented 2 years ago

You have to use model validation check and raise an error message (read docs) - for example

if ($model->load($post)) {
    if (!$model->save()) {
      $out = ['output'=>'<your original value>', 'message'=>'Validation error']
    } else {
      $out = ['output'=>'<your new updated value>', 'message'=>''];
   }
}
// $out = Json::encode($out);