Shahid Thaika
Shahid Thaika

Reputation: 2305

Add additional css class to Yii2 jui datepicker

I am trying to make the text box of jui DatePicker in Yii2 look more like the other text boxes, by adding 'form-control' to the class name of the input control, when rendered.

I tried using clientOptions like this...

'clientOptions' => [ 'class' => 'form-control' ]

'clientOptions' => [ 'className' => 'form-control' ]

...and also as widget options, but am unable to figure this out.

Compared to Bootstrap Datetimepicker, the jui one looks really ugly.

Any ideas how I can add a class or make it look like other textboxes?

I have a simple datepicker, no fancy formattings, but am using it in my model.

Upvotes: 10

Views: 10878

Answers (3)

Sylvester
Sylvester

Reputation: 189

I came across the same problem but

'options' => ['class' => 'form-control']

did not work for me. I resulted to using the CHtml argument called $htmlOptions which is basically an array that holds the attributes of the HTML element and it worked for me.

'htmlOptions'=>array('class'=>'form-control')

Upvotes: 0

It may be given like this.

<?= $form->field($model, 'client_name')->widget(
                    \yii\jui\AutoComplete::classname(), 
                    [
                        'options' => ['class' => 'form-control'],
                        'clientOptions' => [
                            'source' => ['USA', 'RUS'],
                        ],
                    ]
                )?>

Upvotes: 0

Shahid Thaika
Shahid Thaika

Reputation: 2305

Figured it out. It was simply...

'options' => ['class' => 'form-control']

Upvotes: 25

Related Questions