getInputId() public static method

This method converts the result BaseHtml::getInputName into a valid input ID. For example, if BaseHtml::getInputName returns Post[content], this method will return post-content.
public static getInputId ( Model $model, string $attribute ) : string
$model yii\base\Model the model object
$attribute string the attribute name or expression. See [[getAttributeName()]] for explanation of attribute expression.
return string the generated input ID
 public function run()
 {
     $this->view->registerAssetBundle(MultiSelectAsset::className());
     $options = $this->options;
     if (isset($options['id'])) {
         $id = $options['id'];
     } else {
         $id = BaseHtml::getInputId($this->model, $this->attribute);
     }
     if (isset($options['name'])) {
         $name = $options['name'];
     } elseif ($this->hasModel()) {
         $name = BaseHtml::getInputName($this->model, $this->attribute);
     } else {
         $name = $this->name;
     }
     //        if (isset($options['value'])) {
     //            $value = $options['value'];
     //        } elseif ($this->hasModel()) {
     //            $value = BaseHtml::getAttributeValue($this->model, $this->attribute);
     //        } else {
     //            $value = $this->value;
     //        }
     $len = strlen($this->attribute);
     $widget = Html::beginTag('div', ['id' => $id, 'name' => $name]);
     foreach ($this->model as $k => $v) {
         if (substr($k, 0, $len + 1) == $this->attribute . '_') {
             $widget .= Html::activeCheckbox($this->model, $k, ['labelOptions' => ['class' => 'checkbox-inline']]);
         }
     }
     $widget .= Html::endTag('div');
     echo $widget;
 }
Esempio n. 2
0
    /**
     * @param array $options
     * @param bool|TRUE $enclosedByLabel
     * @param string $on_label
     * @param string $off_label
     *
     * @return $this
     */
    public function toggle($options = [], $enclosedByLabel = TRUE, $on_label = 'ON', $off_label = 'OFF')
    {
        if (isset($options['label']) && !isset($this->parts['{label}'])) {
            $this->parts['{label}'] = $options['label'];
            if (!empty($options['labelOptions'])) {
                $this->labelOptions = $options['labelOptions'];
            }
        }
        if ($enclosedByLabel) {
            $this->labelOptions = ['class' => 'c006-block'];
            $this->parts['{input}'] = '
<div class="c006-activeform-toggle-container ' . BaseHtml::getInputId($this->model, $this->attribute) . '" >
    <span class="c006-activeform-toggle-on c006-activeform-on" ><span>' . $on_label . '</span></span>
    <span class="c006-activeform-toggle-off c006-activeform-off"><span>' . $off_label . '</span></span>
    ' . Html::activeHiddenInput($this->model, $this->attribute, $this->inputOptions) . '
</div>
';
        } else {
            unset($options['labelOptions']);
            $options['label'] = NULL;
            $this->parts['{input}'] = '
<div class="c006-activeform-toggle-container ' . BaseHtml::getInputId($this->model, $this->attribute) . '" " >
<div class="table">
    <span class="c006-activeform-toggle-on c006-activeform-on" ><span>ON</span></span>
    <span class="c006-activeform-toggle-off c006-activeform-off"><span>OFF</span></span>
    ' . Html::activeHiddenInput($this->model, $this->attribute, $this->inputOptions) . '
</div>
</div>
';
        }
        $this->adjustLabelFor($options);
        return $this;
    }
 /**
  * @inheritdoc
  */
 public function clientValidateAttribute($model, $attribute, $view)
 {
     $id = BaseHtml::getInputId($model, $attribute);
     $options['id'] = $id;
     $options['min'] = $this->min;
     $options['tooLess'] = $this->tooLess;
     $options['max'] = $this->max;
     $options['tooMore'] = $this->tooMore;
     return 'yii.validation.multiselect(value, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');';
 }
Esempio n. 4
0
    public function clientValidateAttribute($model, $attribute, $view)
    {
        /* @var $model \yii\db\ActiveRecord */
        // Register asset
        PasswordStrengthAsset::register($view);
        $selector = '#' . BaseHtml::getInputId($model, $attribute);
        $message = Json::encode($this->message);
        $options = Json::encode(['message' => $message]);
        $view->registerJs("\$('{$selector}').passwordStrength({$options});", \yii\web\View::POS_READY);
        return <<<JS
\$('{$selector}').passwordStrength('handeValidation', value, messages);
JS;
    }
 public function run()
 {
     $data = $this->model[$this->attribute];
     //определяем картинку в зависимости от типа входных данных стринг/массив
     $imgSrc = '';
     $coords = 'null';
     if (is_array($data)) {
         if (array_key_exists('imgSrc', $data)) {
             $imgSrc = $data['imgSrc'];
         }
         if (array_key_exists('x1', $data) && $data['x1'] != '' && array_key_exists('y1', $data) && $data['y1'] != '' && array_key_exists('x2', $data) && $data['x2'] != '' && array_key_exists('y2', $data) && $data['y2'] != '') {
             $x1 = $data['x1'];
             $y1 = $data['y1'];
             $x2 = $data['x2'];
             $y2 = $data['y2'];
             $coords = '{"x1":' . $x1 . ',"y1":' . $y1 . ',"x2":' . $x2 . ',"y2":' . $y2 . '}';
         }
     } elseif (!empty($data)) {
         $imgSrc = $data;
     }
     //рендерим блок с картинкой
     $previewId = $this->id . '_preview_img';
     $previewImgClass = 'form-img-preview-crop-image';
     $inputId = BaseHtml::getInputId($this->model, $this->attribute);
     if (empty($imgSrc)) {
         $preview = "<div id='{$previewId}'></div>";
     } else {
         $preview = Html::tag('div', Html::img($imgSrc, ['class' => $previewImgClass . ' crop-image', 'data-forinput' => $inputId, 'data-coords' => $coords]), ['id' => $previewId]);
     }
     $this->template = strtr($this->template, ['{preview}' => $preview]);
     //рендерим инпуты
     $inputs = Html::activeTextInput($this->model, $this->attribute . '[imgSrc]', $this->options);
     $inputs .= Html::activeTextInput($this->model, $this->attribute . '[x1]', ['type' => 'hidden']);
     $inputs .= Html::activeTextInput($this->model, $this->attribute . '[y1]', ['type' => 'hidden']);
     $inputs .= Html::activeTextInput($this->model, $this->attribute . '[x2]', ['type' => 'hidden']);
     $inputs .= Html::activeTextInput($this->model, $this->attribute . '[y2]', ['type' => 'hidden']);
     $this->template = strtr($this->template, ['{inputs}' => $inputs]);
     parent::run();
     //css и js
     $view = $this->getView();
     //подключаем ресурсы
     CropImageAsset::register($view);
     //стили для отображения картинки
     $view->registerCss(".{$previewImgClass} {max-width:{$this->imgMaxWidth}; max-height:{$this->imgMaxHeight}}");
     //подключаем файловый менеджер сервера
     $view->registerJs("mihaildev.elFinder.register(" . Json::encode($this->options['id']) . ",\n            function(file, id){\n                UnInitImageAreaSelect('{$inputId}');\n                \$('#' + id).val(file.url);\n                \$('#{$previewId}').html('<img class=\"{$previewImgClass} crop-image\" src=\"'+file.url+'\" data-forinput=\"{$inputId}\" >');\n                \$('#{$previewId} .{$previewImgClass}').load(function(){ InitImageAreaSelect() });\n                return true;}); ");
 }
Esempio n. 6
0
    } else {
        ?>
                        text += '{"key": "' + addslashes($(inputs[0]).val()) + '", "value": "' + addslashes($(inputs[1]).val()) + '"},';
                    <?php 
    }
    ?>
                }

                <?php 
    if ($widget->unique) {
        ?>
                    text = (text == '' ? '{}' : "{" + text.substr(0, text.length-1) + '}');
                <?php 
    } else {
        ?>
                    text = (text == '' ? '[]' : "[" + text.substr(0, text.length-1) + ']');
                <?php 
    }
    ?>

                $('#<?php 
    echo BaseHtml::getInputId($widget->model, $widget->attribute);
    ?>
').val(text);
            });
        <?php 
}
?>
    });
</script>
 public function actionLoadchain()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model = new Restaurant();
     $map = new \common\models\ResMap();
     if ($model->load(Yii::$app->request->post())) {
         $chaindata = $model->chainCity;
         $chainmapstatus = $chaindata->chainFieldStatusMaps;
         \yii::trace(print_r($chainmapstatus, true));
         $finalmap = [];
         foreach ($model->chainFieldMap() as $map) {
             $map['id'] = \yii\helpers\BaseHtml::getInputId($model, $map['id']);
             $map['lock'] = $chainmapstatus->{$map['value']};
             $map['value'] = $chaindata->{$map['value']};
             $finalmap[] = $map;
         }
         return ['responce' => ['map' => $finalmap]];
     } else {
         return ['responce' => 'false'];
     }
 }
 protected function getInput($type, $list = false)
 {
     if ($this->hasModel()) {
         if (isset($this->options['maxlength']) && $this->options['maxlength'] === true) {
             unset($this->options['maxlength']);
             foreach ($this->model->getActiveValidators($this->attribute) as $validator) {
                 if ($validator instanceof StringValidator && $validator->max !== null) {
                     $this->options['maxlength'] = $validator->max;
                     break;
                 }
             }
         }
         if ($this->submit) {
             $this->name = isset($this->options['name']) ? $this->options['name'] : BaseHtml::getInputName($this->model, $this->attribute);
         }
         $this->value = isset($this->options['value']) ? $this->options['value'] : BaseHtml::getAttributeValue($this->model, $this->attribute);
         if (!array_key_exists('id', $this->options)) {
             $this->options['id'] = BaseHtml::getInputId($this->model, $this->attribute);
         }
     }
     return Html::textInput($this->name, $this->value, $this->options);
 }