wbraganca / yii2-dynamicform & amp; & amp; Картик-v / yii2-виджет-colorinput

Я пытаюсь использовать colorpicker в динамической форме и когда я добавляю новое поле — новое colorpicker не работает..

Итак, я думаю, я должен заново инициализировать все colorpickers когда новое поле добавлено afterInsert событие? Как это сделать правильно?

Мой файл просмотра:

<?php
use kartik\color\ColorInput;
use wbraganca\dynamicform\DynamicFormWidget;
use yii\bootstrap\Html;
?>
<div class="block-wrapper">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'line_wrapper',
'widgetBody' => '.container-lines',
'widgetItem' => '.item',
'insertButton' => '.add-line',
'deleteButton' => '.remove-line',
'model' => $lines[0],
'formId' => $form->id,
'formFields' => [
'color',
],
]); ?>
<div class="container-lines">
<button type="button" class="add-line hidden"></button>
<?php foreach ($lines as $i => $line): ?>
<div class="item line-block">
<button type="button" class="remove-line hidden"></button>
<?php if (!$line->isNewRecord) : ?>
<?= Html::activeHiddenInput($line, "[{$i}]id") ?>
<?php endif ?>
<?= $form->field($line, "[{$i}]color")->widget(ColorInput::classname(), [
'value' => $line->color,
'options' => [
'readonly' => true,
],
'pluginOptions' => [
'showInput' => true,
'showInitial' => true,
'showPalette' => true,
'showPaletteOnly' => true,
'showSelectionPalette' => true,
'showAlpha' => false,
'allowEmpty' => false,
'preferredFormat' => 'hex6',
],
])->label(false) ?>
</div>
<?php endforeach ?>
</div>
<?php DynamicFormWidget::end() ?>
</div>
<?php
$js = '
$(".line_wrapper").on("afterInsert", function() {

$(".spectrum-input.form-control").each(function() {
$("#line-" + this.id + "-color-cont").spectrum("destroy");
});
$(".spectrum-input.form-control").each(function() {
var id =  this.id
kvInitHtml5("#line-" + id + "-color","#line-" + id + "-color-source");
$.when($("#line-" + id + "-color-source").spectrum(spectrum_40c44e64))
.done(function(){
$("#line-" + id + "-color-source").spectrum("set",
$("#line-" + id + "-color").val()
);
$("#line-" + id + "-color-cont").removeClass("kv-center-loading");
});
});
});
';
$this->registerJs($js);

Кто нибудь сталкивался с такой проблемой?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector