jquery Yii2 KartikV color input how to get selected color value from different input fields

qmb5sa22  于 2022-11-03  发布在  jQuery
关注(0)|答案(1)|浏览(135)

我正在使用KartikV颜色输入部件为Yii2高级,我有很多的颜色输入字段在我的形式。我如何才能得到新的选择颜色的值后,每次选择不同的颜色输入。这主要是我需要选择颜色的一些选项,并在画布上绘制与此选定的颜色。之后,我必须从不同的输入中选择另一种颜色,并继续在画布上绘制,但现在使用新选择的颜色值。用于绘图的jQuery脚本已经准备好了,但是需要在每次输入更改后分配选定的颜色。
一个颜色选择行的示例:

<div class="row skin-condition-select-sections">
                                <div class="col-md-4">
                                    <?= $form->field($skin_condition_model, 'head_skin_scars')
                                        ->widget(ColorInput::classname(), [
                                            'showDefaultPalette' => false,
                                            'options' => ['placeholder' => '   ',],
                                            'addon' => ['append' => [
                                                'content' => Html::button('Go', [
                                                    'class' => 'btn btn-primary color-picker'
                                                ]), 'asButton' => true]
                                            ],
                                            'pluginOptions' => [
                                                'showInput' => true,
                                                'showInitial' => true,
                                                'showPalette' => true,
                                                'showPaletteOnly' => true,
                                                'showSelectionPalette' => true,
                                                'showAlpha' => false,
                                                'allowEmpty' => true,
                                                'preferredFormat' => 'name',
                                                'palette' => [
                                                    [
                                                        "black", "grey", "maroon", "magenta",
                                                    ],
                                                    [
                                                        "red", "orange", "yellow", "indigo",
                                                    ],
                                                    [
                                                        "blue", "green", "cyan",
                                                    ],
                                                ]
                                            ]
                                        ])->label(false) ?>
                                </div>
                                <div class="col-md-4 text-center ">
                                    <h5><?= Yii::t('app', 'Scars/Scratches') ?></h5>
                                </div>
                                <div class="col-md-4">
                                    <?= $form->field($skin_condition_model, 'face_skin_scars')
                                        ->widget(ColorInput::classname(), [
                                            'showDefaultPalette' => false,
                                            'options' => ['placeholder' => '   '],
                                            'pluginOptions' => [
                                                'showInput' => true,
                                                'showInitial' => true,
                                                'showPalette' => true,
                                                'showPaletteOnly' => true,
                                                'showSelectionPalette' => true,
                                                'showAlpha' => false,
                                                'allowEmpty' => true,
                                                'preferredFormat' => 'name',
                                                'palette' => [
                                                    [
                                                        "black", "grey", "maroon", "magenta",
                                                    ],
                                                    [
                                                        "red", "orange", "yellow", "indigo",
                                                    ],
                                                    [
                                                        "blue", "green", "cyan",
                                                    ],
                                                ]
                                            ]
                                        ])->label(false) ?>
                                </div>
                            </div>
anauzrmj

anauzrmj1#

因为这个表单是在modal中生成的,我在html中没有这些值,所以我在open modal之后添加了JS来获取这些值

$('#skinModal').click(function (){
        $( ".spectrum-input" ).change(function() {
            color = $(this).val();
        });
    })

相关问题