use app\helpers\Icon; use app\widgets\ActiveForm; use app\widgets\InputGroup; use yii\bootstrap\Button; use yii\helpers\Html; use yii\web\JsExpression; /** @var $this yii\web\View */ /** @var $form app\widgets\ActiveForm */ /** @var $model app\forms\user\Profile */ /** @var $emailId string */ $emailId = Html::getInputId($model, 'email'); $form = ActiveForm::begin(['id' => 'user-profile-form', 'pjax' => true, 'layout' => 'horizontal', 'enableClientValidation' => true, 'fieldConfig' => ['horizontalCssClasses' => ['label' => 'col-sm-2', 'wrapper' => 'col-sm-10']]]); ?> <?php echo $form->field($model, 'email')->widget(InputGroup::className(), ['inputOptions' => ['class' => 'form-control', 'disabled' => 'disabled'], 'button' => true, 'addon' => Button::widget(['label' => Icon::icon('glyphicon glyphicon-copy'), 'encodeLabel' => false, 'options' => ['class' => 'btn btn-default btn-flat'], 'clientEvents' => ['click' => new JsExpression("function (ev) {\n ev.preventDefault();\n \$('#{$emailId}').removeAttr('disabled').select();\n document.execCommand('copy');\n \$('#{$emailId}').attr('disabled', 'disabled');\n }")]])]); ?> <?php echo $form->field($model, 'name'); ?> <?php echo $form->field($model, 'password')->passwordInput(); ?> <?php echo $form->field($model, 'password_repeat')->passwordInput(); ?> <?php ActiveForm::endWithActions(['cancel' => false]); ?>
/** * @inheritdoc */ public function run() { $this->addon = Button::widget(['label' => Icon::icon($this->icon), 'options' => $this->buttonOptions, 'encodeLabel' => false, 'clientEvents' => ['click' => new JsExpression("\n function (ev) {\n ev.preventDefault();\n jQuery('#{$this->inputOptions['id']}').val('');\n }\n ")]]); return parent::run(); }