2amigos / yii2-selectize-widget

Selectize From Brian Reavis Yii2 Widget
Other
73 stars 41 forks source link

Using with form #16

Closed mtangoo closed 9 years ago

mtangoo commented 9 years ago

Hi, thanks for nice sets of Widgets. Can this widget be used with form?

tonydspaniard commented 9 years ago

Sure!

mtangoo commented 9 years ago

can you give me an example? This one does not work properly (No list at all)

<?= $form->field($model, 'category')->widget(SelectizeDropDownList::className(), [
        'value'=>['Stefano', 'Upendo', 'Hilkia', 'Moshe'],
    ]) ?>
tonydspaniard commented 9 years ago

Yep:


<?= $form->field($model, 'tags')->widget(SelectizeDropDownList::className(), [
    'clientOptions' => [
        // ...
    ],
);?> 

The value should be the set on the $model->tags attribute on this case (ie $model->tags =['love', 'this', 'game'];)

mtangoo commented 9 years ago

it just does not work. I have checked print_r($model->tags); and I get Array ( [0] => love [1] => this [2] => game ) but the Widget have nothing on it I use

 <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'content')->widget(CKEditor::className(), [ 
        'preset' => 'basic' 
    ])
    ->label(false) ?>

    <?= $form->field($model, 'tags')->widget(SelectizeDropDownList::className(), [
        'clientOptions' => [
            // ...
        ],
    ]) ?> 

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>
mtangoo commented 9 years ago

It needs "items" attribute. Please update the docs to save others of my pain

           <?= $form->field($model, 'category')->widget(SelectizeDropDownList::className(), [ 
                'items'=>$model->tags,
                'clientOptions' => [
                    // ...
                ],
            ]) ?> 
tonydspaniard commented 9 years ago

Will do, thanks @mtangoo