Uncaught TypeError: html.replace is not a function
japhethmutai opened this issue · 2 comments
japhethmutai commented
I am getting this error consistently trying to save data from a GridView column. Nothing is saved to database neither does it reload the page. How can I resolve this?
Gridview column Attribute:
[
'class' => 'kartik\grid\EditableColumn',
'attribute' => 'test_results',
'vAlign' => 'middle',
// 'readonly' => function($model, $key, $index, $widget) {
// return (!$model->status); // do not allow editing of inactive records
// },
'editableOptions'=>[
'header'=>'Results',
'inputType'=>\kartik\editable\Editable::INPUT_TEXT,
],
],
Controller Action:
public function actionIndex()
{
$searchModel = new PatientLabTestsSearch;
$dataProvider = $searchModel->search(Yii::$app->request->getQueryParams());
// validate if there is a editable input saved via AJAX
if (Yii::$app->request->post('hasEditable')) {
// instantiate your book model for saving
$patient_lab_test_item_id = Yii::$app->request->post('editableKey');
$model = PatientLabTestItems::findOne($patient_lab_test_item_id);
// store a default json response as desired by editable
$out = Json::encode(['output'=>'', 'message'=>'']);
// fetch the first entry in posted data (there should only be one entry
// anyway in this array for an editable submission)
// - $posted is the posted data for Book without any indexes
// - $post is the converted array for single model validation
$posted = current($_POST['PatientLabTestItems']);
$post = ['PatientLabTestItems' => $posted];
// load model like any single model validation
if ($model->load($post)) {
// can save model or do something before saving model
$model->save();
// custom output to return to be displayed as the editable grid cell
// data. Normally this is empty - whereby whatever value is edited by
// in the input by user is updated automatically.
$output = '';
// similarly you can check if the name attribute was posted as well
// if (isset($posted['name'])) {
// $output = ''; // process as you need
// }
$out = Json::encode(['output'=>$output, 'message'=>'']);
}
// return ajax json encoded response and exit
echo $out;
die;
}
return $this->render('index', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
]);
}
japhethmutai commented
I realized my problem. Sorry, was editing the wrong action.
MauroShek commented
Hello, how did it?