yii2-multiple-input icon indicating copy to clipboard operation
yii2-multiple-input copied to clipboard

Kartik DateControl Does not work with TabularInput Widget

Open IvandaNothabeer opened this issue 4 years ago • 1 comments

see #215 Symptoms are the same. ( The Hidden field behind date control does not have an index number included in the field name ) Either the problem is back or it didn't really go away.


Possible temporary workaround is to add a hidden column to the TabularInput widget configuration which substitutes for the incorrectly named fields ...

					[
						'name'  => 'date',
						'title' => 'Date',
						'type'  => DateControl::className(),
						'options' => [
							'type' => DateControl::FORMAT_DATE,
							'pluginOptions' => [
								'todayHighlight' => true,
							],
			                'widgetOptions' => [
								'type' => DatePicker::TYPE_COMPONENT_PREPEND,
							],
						]
					],
                                       // Add Extra Hidden field to substitute for missing Date {multiple_index} 
					[
						'name' => 'date',
						'type' =>  \unclead\multipleinput\MultipleInputColumn::TYPE_HIDDEN_INPUT,
					],

Note however that the returned POST data will contain an extra "date" field ( containing a single date from the last row ) after the data[] array. This can be be removed in your controller code before updating the records.


			$data = Yii::$app->request->post('Transaction', []);
			$models = [];
			foreach (array_keys($data) as $index) {
				$models[$index] = new app\models\Transaction();
			}
			if (Model::loadMultiple($models, Yii::$app->request->post())) {
				unset($models['date']);
				if ( Model::validateMultiple($models)) {
					foreach ($models as $model) {
						$model->save(false);
					}
				}

[ Also want to say this is an awesome widget. Thanks to original author for all the hard work]

IvandaNothabeer avatar Oct 11 '20 21:10 IvandaNothabeer

@IvandaNothabeer thx for reporting an issue. according to a comment from the closed issue, the problem has been fixed. May be something changed in kartik's library and the original issue came back Anyway somebody has to investigate it. The widget's code isn't complicated and probably this person can be you 😄 I didn't touch the widget's code and yii2 in general for a long time and TBH I'm a bit of out of context already

unclead avatar Oct 14 '20 17:10 unclead