Ragheb AlKilany
Ragheb AlKilany

Reputation: 933

Yii2 Color Picker in Form

Is there any built in class or an extinction that makes the user pick color from something like this?

Colour Picker

Upvotes: 1

Views: 6298

Answers (3)

m50
m50

Reputation: 816

Now, you can simply use HTML5 color picker by setting the input type to color.

<?= $form->field($model, 'color_code')->textInput(['maxlength' => true,'type'=>'color']) ?>

Upvotes: 0

Dency G B
Dency G B

Reputation: 8146

You can simply render a color input like this with out using any plugins.

<?= $form->field($model, 'color', [
    'template' => "{input}"
    ])->input('color',['class'=>"input_class"]) ?>

Upvotes: 5

GAMITG
GAMITG

Reputation: 3818

You can use kartik\widgets\ColorInput widget. first install kartik\widgets\ColorInput from this link

e.g. (Updated)

use kartik\widgets\ColorInput; or kartik\color\ColorInput;(for previous ver.)

<?php $form = ActiveForm::begin([
    'id' => 'form',
]); ?>

    <?= $form->field($model, 'color_code')->widget(ColorInput::classname(), ['options' => ['placeholder' => 'Select Color...'],]); ?>

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

<?php ActiveForm::end(); ?>

Upvotes: 3

Related Questions