Answer the question
In order to leave comments, you need to log in
How to output data in yii2-multiple-input widget after save?
For half a day I have been suffering with the output of data through the yii2-multiple-input widget does not want to work.
There are few examples in the documentation for me personally.
The data is stored in my database in 5 cells.
Before adding any entry via MultipleInput, there are no errors and the form on the page works as it should. As soon as I add at least 1 record (or 5), the form works out, everything is saved to the database and the page with the error stops opening:
Error
Call to a member function hasErrors() on array
1. in W:\domains\finderlot.ru\yii2\vendor\yiisoft\yii2\widgets\ActiveField.php
<?= $form->field($model_price_change, 'prices_list')->widget(MultipleInput::className(), [
'id' => 'price_change',
'max' => 50,
'min' => 0,
'allowEmptyList' => false,
'enableGuessTitle' => true,
'sortable' => true,
//'data' => $model_price_change,
'columns' => [
[
'name' => 'date_start',
'title' => 'Дата начала',
'type' => DateTimePicker::className(),
'options' => [
'pluginOptions' => [
'minView' => '3',
'maxView' => '3',
'format' => 'dd.mm.yyyy hh:ii:ss', // формат который будет передаваться в базу
'autoclose' => true,
'weekStart' => 1,
'startDate' => date('01.01.2020'), //дата ниже которой нельзя установить значение
]
]
],
[
'name' => 'date_end',
'title' => 'Дата окончания',
'type' => DateTimePicker::className(),
// 'value' => function($data) {
// return $data['date_end'];
// },
'options' => [
'pluginOptions' => [
'minView' => '3',
'maxView' => '3',
'format' => 'dd.mm.yyyy hh:ii:ss', // формат который будет передаваться в базу
'autoclose' => true,
'weekStart' => 1,
'startDate' => date('01.01.2020'), //дата ниже которой нельзя установить значение
]
]
],
[
'name' => 'price',
'title' => 'Цена',
'type' => 'textInput',
// 'value' => function($data) {
// return $data['price'];
// },
'options' => [
'placeholder' => 'В рублях',
]
],
[
'name' => 'deposit',
'title' => 'Задаток',
'type' => 'textInput',
// 'value' => function($data) {
// return $data['deposit'];
// },
'options' => [
'placeholder' => 'В рублях',
]
],
],
'iconSource' => 'fa',
'addButtonOptions' => [
'class' => 'btn btn-success',
],
'addButtonPosition' => MultipleInput::POS_HEADER
])
->label(false);
?>
$model_price_change = oldPrices::find()->where(['lot_id' => $id])->all();
if($model_price_change == null && empty($model_price_change))
{
return new oldPrices();
} else {
return $model_price_change;
}
public $prices_list;
public function rules()
{
return [
[['price', 'deposit'], 'string'],
[['created_at', 'updated_at', 'date_start', 'date_end', 'prices_list'], 'safe'],
];
}
Answer the question
In order to leave comments, you need to log in
$model_price_change must contain one model:
<?= $form->field($model_price_change, 'prices_list')
$model_price_change = oldPrices::find()->where(['lot_id' => $id])->all();
$model_price_change = oldPrices::findOne(['lot_id' => $id]);
$model_price_change = new FormModel();
$model_price_change->prices_list= oldPrices::find()->where(['lot_id' => $id])->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question