widgets kartik disabled bootstrap php gridview yii datepicker yii2

php - disabled - Yii2 datepicker en kartik gridview no funciona



yii widget datepicker (2)

Estoy usando kartik gridview y quiero agregar un datepicker a los campos de búsqueda. También estoy usando datecontrol.

Esto es lo que obtuve, pero la validación no está funcionando:

Selector de fecha de Gridview:

[ ''attribute''=>''date'', ''value'' => function ($model, $index, $widget) { return Yii::$app->formatter->asDate($model->date); }, ''filterType'' => GridView::FILTER_DATE, ''filterWidgetOptions'' => [ ''pluginOptions'' => [ ''format'' => ''dd-mm-yyyy'', ''autoclose'' => true, ''todayHighlight'' => true, ] ], ''width'' => ''160px'', ''hAlign'' => ''center'', ],

Configuración de Datecontrol:

''datecontrol'' => [ ''class'' => ''kartik/datecontrol/Module'', // format settings for displaying each date attribute (ICU format example) ''displaySettings'' => [ Module::FORMAT_DATE => ''php:d-m-Y'', Module::FORMAT_TIME => ''php:H:m:s a'', Module::FORMAT_DATETIME => ''dd-MM-yyyy HH:mm:ss a'', ], // format settings for saving each date attribute (PHP format example) ''saveSettings'' => [ Module::FORMAT_DATE => ''php:U'', // saves as unix timestamp Module::FORMAT_TIME => ''php:H:i:s'', Module::FORMAT_DATETIME => ''php:Y-m-d H:i:s'', ], // set your display timezone ''displayTimezone'' => ''Europe/Brussels'', // set your timezone for date saved to db ''saveTimezone'' => ''Europe/Brussels'', // automatically use kartik/widgets for each of the above formats ''autoWidget'' => true, // default settings for each widget from kartik/widgets used when autoWidget is true ''autoWidgetSettings'' => [ Module::FORMAT_DATE => [''pluginOptions'' => [ ''autoclose'' => true, ''todayHighlight'' => true, //''todayBtn'' => true ]], Module::FORMAT_DATETIME => [], // setup if needed Module::FORMAT_TIME => [], // setup if needed ], // Use custom convert action ''convertAction'' => ''/cms/parse/convert-date-control'' ],

Searchmodel:

<?php namespace infoweb/news/models; use Yii; use yii/base/Model; use yii/data/ActiveDataProvider; /** * NewsSearch represents the model behind the search form about `infoweb/empoyees/models/News`. */ class NewsSearch extends News { /** * @inheritdoc */ public function rules() { return [ [[''active''], ''integer''], [[''title'', ''date''], ''safe''], ]; } /** * @inheritdoc */ public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } /** * Creates data provider instance with search query applied * @return ActiveDataProvider */ public function search($params) { // Transform the date to a unix timestamp for usage in the search query if (isset($params[''NewsSearch''][''date''])) { $origDate = $params[''NewsSearch''][''date'']; $params[''NewsSearch''][''date''] = strtotime($params[''NewsSearch''][''date'']); } $query = News::find(); $query->andFilterWhere([''language'' => Yii::$app->language]); $dataProvider = new ActiveDataProvider([ ''query'' => $query, ''sort'' => [''defaultOrder'' => [''date'' => SORT_ASC]], ''pagination'' => [ ''pageSize'' => 50, ], ]); // Join the entity model as a relation $query->joinWith([''translations'']); // enable sorting for the related column $dataProvider->sort->attributes[''title''] = [ ''asc'' => [''title'' => SORT_ASC], ''desc'' => [''title'' => SORT_DESC], ]; if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere([ ''id'' => $this->id, ''date'' => $this->date, ''active'' => $this->active, ''created_at'' => $this->created_at, ''updated_at'' => $this->updated_at, ]); $query->andFilterWhere([''like'', ''title'', $this->title]); // Format the date for display if (isset($params[''NewsSearch''][''date''])) { $this->date = $origDate; } return $dataProvider; } }

Pantalla:


Añadir en reglas

[[''title'',''date''], ''safe''],


añadir

// Convert date to Unix timestamp if (!empty($params[StringHelper::basename(self::className())][''date''])) { $query->andFilterWhere([ ''date'' => strtotime($params[StringHelper::basename(self::className())][''date'']) ]); }

después

if (!($this->load($params) && $this->validate())) { return $dataProvider; }

y agrega [[''date''], ''safe''], a tus reglas