简体   繁体   中英

How do I set template and labelOptions for Select2?

How to set my template and labelOptions in Select2 in Yii2? For a regular field, this can be done via field->labelOptions and field->template. And how to do it for Select2?

$form->field($model, 'test',[
    'labelOptions' => ['style' => 'display:none !important;'],
    'template' => '{label}{input}{error}'])
    ->radioButtonGroup($data, ['itemOptions' => ['class' => 'btn btn-default', 'style' => 'display:none !important;']
]); ?>

Select2, which is in question: https://demos.krajee.com/widget-details/select2

I asked the question himself and answered it himself, and even in the question itself. It was enough to do as in the example from the question - set field->template and field->label Options as needed:

$form->field($model, 'test', [
    'template' => '{label}{input}{error}'
])->widget(Select2::classname(), [
    'data' => $data,
    'pluginOptions' => [
        'allowClear' => true
    ],
]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM