public function run() { parent::run(); $this->registerAssets(); $view = $this->getView(); $id = $this->getId(); $output = ''; $output .= Html::input('hidden', $this->inputName, null, ['id' => $this->inputId]); $output .= Html::beginTag('div', ['class' => 'row']); $output .= Html::beginTag('div', ['class' => 'col-xs-12']); $output .= Html::tag('canvas', '', ['class' => ['signature-input-canvas'], 'style' => ['border' => '1px solid black', 'width' => '100%']]); $output .= Html::endTag('div'); $output .= Html::beginTag('div', ['class' => 'col-xs-12']); $output .= Html::button(\Yii::t('app', 'Clear'), ['class' => ['col-xs-12', 'btn', 'btn-default'], 'id' => $id . '-clear']); $output .= Html::endTag('div'); $output .= Html::endTag('div'); $view->registerJs(<<<JS \$(function(){ var canvas = \$("#{$id} .signature-input-canvas")[0]; var signaturePad = new SignaturePad(canvas); signaturePad.onEnd = function(){ var result = signaturePad.toDataURL(); \$('#{$this->inputId}').val(result); }; \$('#{$id}-clear').on('click', function(){ \$('#{$this->inputId}').val(''); signaturePad.clear(); }); }) JS ); return Html::tag('div', $output, ['id' => $id, 'class' => ['signature-input']]); }
/** * @throws \yii\base\InvalidConfigException */ public function init() { parent::init(); $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value; $this->momentDatetimeFormat = $this->momentDatetimeFormat ?: ArrayHelper::getValue($this->getPhpMomentMappings(), $this->phpDatetimeFormat); if (!$this->momentDatetimeFormat) { throw new InvalidConfigException('Please set momentjs datetime format'); } // Init default clientOptions $this->clientOptions = ArrayHelper::merge(['useCurrent' => true, 'locale' => $this->locale ?: substr(Yii::$app->language, 0, 2), 'format' => $this->momentDatetimeFormat], $this->clientOptions); // Init default options $this->options = ArrayHelper::merge(['class' => 'form-control'], $this->options); if ($value !== null) { $this->options['value'] = array_key_exists('value', $this->options) ? $this->options['value'] : Yii::$app->formatter->asDatetime($value, $this->phpDatetimeFormat); } if (!isset($this->containerOptions['id'])) { $this->containerOptions['id'] = $this->getId(); } $this->registerJs(); }
/** * @inheritdoc */ protected function registerPlugin($name) { $asset = CheckAsset::register($this->getView()); $asset->style = $this->style; $class = $this->type === static::TYPE_CHECKBOX ? 'checkboxClass' : 'radioClass'; $this->clientOptions[$class] = 'i' . $this->type . '_' . $this->style . '-' . $this->color; parent::registerPlugin($name); }
/** * @inheritdoc */ public function init() { parent::init(); Bootstrap3WysiwygAsset::register($this->getView()); $this->registerPlugin('wysihtml5'); }
/** * @inheritdoc */ public function init() { parent::init(); $this->inputOptions['id'] = $this->options['id']; $this->options['id'] = $this->getId(); }