本文整理汇总了PHP中yii\widgets\ActiveForm::field方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveForm::field方法的具体用法?PHP ActiveForm::field怎么用?PHP ActiveForm::field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\widgets\ActiveForm
的用法示例。
在下文中一共展示了ActiveForm::field方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderInput
/**
* Формирование Html кода поля для вывода в форме
* @param ActiveForm $form объект форма
* @param array $options массив html атрибутов поля
* @param bool|int $index инднкс модели при табличном вводе
* @return string
*/
public function renderInput(ActiveForm $form, array $options = [], $index = false)
{
$options = ArrayHelper::merge($this->options, $options);
$attr = $this->modelField->attr;
$defaults = ["maxFileSize" => $this->modelField->model->maxFileSize, "uploadRoute" => $this->defaultRoute];
$widgetOptions = ArrayHelper::merge($defaults, $this->widgetOptions, ["options" => $options]);
$attr = $this->getFormAttrName($index, $attr);
return $form->field($this->modelField->model, $attr)->widget(Html5Widget::className(), $widgetOptions);
}
示例2: submitDropdown
/**
* Button with multiple submit options.
* @param ActiveForm $form
* @param $model
* @param $attribute
* @param $items
* @param string $content
* @param array $options
* @return string
*/
public static function submitDropdown(ActiveForm $form, $model, $attribute, $items, $content = "Save", $options = [])
{
if (count($items) == 1) {
return $form->field($model, $attribute, ['options' => ['class' => 'pull-left']])->label(false)->hiddenInput(['value' => key($items)]) . Html::submitButton(reset($items), $options);
}
$lis = '';
foreach ($items as $key => $name) {
$lis .= Html::tag('li', "<a href='#'>{$name}</a>", ['onclick' => "\$(this).closest('div').find('input').val('{$key}');\n \$(this).parents('form').submit();", 'class' => $model->{$attribute} == $key ? 'active' : '']);
}
return Html::beginTag('div', ['class' => 'btn-group']) . $form->field($model, $attribute, ['options' => ['class' => 'pull-left']])->label(false)->hiddenInput() . Html::button($content . '<span class="caret"></span>', ['class' => 'btn dropdown-toggle btn-primary', "data-toggle" => "dropdown"]) . Html::beginTag('ul', ['class' => 'dropdown-menu']) . $lis . Html::endTag('ul') . Html::endTag('div');
}
示例3: run
/**
* @inheritdoc
*/
public function run()
{
parent::init();
ListInputAsset::register($this->view);
$pluginOptions = Json::encode($this->pluginOptions);
$this->view->registerJs(sprintf('$("#%s").listinput(%s)', $this->options['id'], $pluginOptions));
if ($this->hasModel()) {
if ($this->form == null) {
throw new InvalidConfigException(__CLASS__ . '::$form must be specifed.');
}
return $this->form->field($this->model, $this->attribute, ['template' => $this->template])->textInput($this->options);
} else {
return Html::textInput($this->name, $this->value, $this->options);
}
}
示例4: renderInput
/**
* Формирование Html кода поля для вывода в форме
* @param ActiveForm $form объект форма
* @param array $options массив html атрибутов поля
* @param bool|int $index инднкс модели при табличном вводе
* @return string
*/
public function renderInput(ActiveForm $form, array $options = [], $index = false)
{
$options = ArrayHelper::merge($this->options, $options);
$widgetOptions = ArrayHelper::merge(["visibleOptions" => ["class" => "form-control"]], $this->widgetOptions, ["options" => $options]);
$attr = $this->getFormAttrName($index, $this->modelField->attr);
return $form->field($this->modelField->model, $attr)->widget(AutoComplete::className(), $widgetOptions);
}
示例5: renderConfigForm
public function renderConfigForm(ActiveForm $activeForm)
{
echo $activeForm->field($this, 'isLive')->checkbox();
echo $activeForm->field($this, 'sMerchantLogin')->textInput();
echo $activeForm->field($this, 'sMerchantPass1')->textInput();
echo $activeForm->field($this, 'sMerchantPass2')->textInput();
}
示例6: renderInput
/**
* Формирование Html кода поля для вывода в форме
* @param ActiveForm $form объект форма
* @param array $options массив html атрибутов поля
* @param bool|int $index инднкс модели при табличном вводе
* @return string
*/
public function renderInput(ActiveForm $form, array $options = [], $index = false)
{
$options = ArrayHelper::merge($this->options, $options);
$widgetOptions = ArrayHelper::merge($this->widgetOptions, ["options" => $options]);
$attr = $this->getFormAttrName($index, $this->modelField->attr);
return $form->field($this->modelField->model, $attr)->widget(MarkItUp::className(), $widgetOptions);
}
示例7: getExtendedFilterForm
/**
* @inheritdoc
*/
public function getExtendedFilterForm(ActiveForm $form, array $options = [])
{
$data = $this->defaultGridFilter();
if (!isset($options['prompt'])) {
$options['prompt'] = '';
}
return $form->field($this->model, $this->attr)->dropDownList($data, $options);
}
示例8: testBooleanAttributes
public function testBooleanAttributes()
{
$o = ['template' => '{input}'];
$model = new DynamicModel(['name']);
ob_start();
$form = new ActiveForm(['action' => '/something']);
ob_end_clean();
$this->assertEquals(<<<EOF
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]" required>
</div>
EOF
, (string) $form->field($model, 'name', $o)->input('email', ['required' => true]));
$this->assertEquals(<<<EOF
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]">
</div>
EOF
, (string) $form->field($model, 'name', $o)->input('email', ['required' => false]));
$this->assertEquals(<<<EOF
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]" required="test">
</div>
EOF
, (string) $form->field($model, 'name', $o)->input('email', ['required' => 'test']));
}
示例9: run
/**
* @inheritdoc
*/
public function run()
{
$id = Html::getInputId($this->model, 'image_deleted');
$options = ['options' => ['accept' => 'image/*'], 'pluginOptions' => ['showUpload' => false], 'pluginEvents' => ['fileclear' => "function() { \$('#{$id}').val(1);}"]];
if ($this->model->imageUrl !== null) {
$options['pluginOptions']['initialPreview'] = [Html::img($this->model->imageUrl, ['class' => 'file-preview-image'])];
}
echo $this->form->field($this->model, 'image_deleted', ['template' => '{input}'])->hiddenInput();
echo $this->form->field($this->model, 'image')->widget(FileInput::classname(), $options);
}
示例10: renderInput
/**
* Формирование Html кода поля для вывода в форме
* @param ActiveForm $form объект форма
* @param array $options массив html атрибутов поля
* @param bool|int $index инднкс модели при табличном вводе
* @return string
*/
public function renderInput(ActiveForm $form, array $options = [], $index = false)
{
$options = ArrayHelper::merge($this->options, $options);
$widgetOptions = ArrayHelper::merge(["options" => ["class" => "form-control"]], $this->widgetOptions, ["options" => $options]);
$fieldOptions = ["options" => ["class" => "form-group col-xs-6"]];
$html = Html::beginTag('div', ['class' => 'row']);
$html .= $form->field($this->modelField->model, $this->fromAttr, $fieldOptions)->widget(DatePicker::className(), $widgetOptions);
$html .= $form->field($this->modelField->model, $this->toAttr, $fieldOptions)->widget(DatePicker::className(), $widgetOptions);
$html .= Html::endTag('div');
return $html;
}
示例11: renderInput
/**
* Формирование Html кода поля для вывода в форме
* @param ActiveForm $form объект форма
* @param array $options массив html атрибутов поля
* @param bool|int $index инднкс модели при табличном вводе
* @return string
*/
public function renderInput(ActiveForm $form, array $options = [], $index = false)
{
$data = $this->modelField->getDataValue();
if (empty($data)) {
return false;
}
$options = ArrayHelper::merge($this->options, $options, ["multiple" => true]);
$widgetOptions = ArrayHelper::merge(["data" => $data], $this->widgetOptions, ["options" => $options]);
$attr = $this->getFormAttrName($index, $this->modelField->attr);
return $form->field($this->modelField->model, $attr)->widget(MultiSelect::className(), $widgetOptions);
}
示例12: renderConfigForm
public function renderConfigForm(ActiveForm $form)
{
echo $form->fieldSet(\Yii::t('skeeks/seo', 'Keywords'));
echo $form->field($this, 'kladrApiToken');
echo $form->field($this, 'kladrRequestLimit');
echo $form->field($this, 'russiaId')->listBox(\yii\helpers\ArrayHelper::map(\skeeks\cms\kladr\models\KladrLocation::find()->where(['type' => \skeeks\cms\kladr\models\KladrLocation::TYPE_COUNTRY])->all(), 'id', 'name'), ['size' => 1]);
echo $form->fieldSetEnd();
}
示例13: run
/**
* @inheritdoc
*/
public function run()
{
Asset::register($this->view);
$config = empty($this->config) ? json_encode(['locale' => \Yii::$app->language]) : json_encode($this->config);
$this->view->registerJs(sprintf('$("#%s").passField(%s)', $this->options['id'], $config));
if ($this->hasModel()) {
if ($this->form == null) {
throw new InvalidConfigException(__CLASS__ . '.form property must be specified');
}
return $this->form->field($this->model, $this->attribute)->passwordInput($this->options);
} else {
return Html::passwordInput($this->name, $this->value, $this->options);
}
}
示例14: run
public function run()
{
echo $this->form->field($this->model, $this->model->getCountryPropertyName())->dropDownList(ArrayHelper::map(Country::find()->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), ['id' => 'location_country_id', 'prompt' => Yii::t('common/geo/country', 'Select country')]);
if ($this->localized === $this->model->getCountryPropertyName()) {
return;
}
echo $this->form->field($this->model, $this->model->getRegionPropertyName())->widget(DepDrop::className(), ['options' => ['id' => 'location_region_id', 'placeholder' => Yii::t('common/geo/region', 'Select region')], 'data' => ArrayHelper::map(Region::find()->where(['country_id' => $this->model->country_id])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), 'pluginOptions' => ['url' => Url::to(['/geo/region/list']), 'depends' => ['location_country_id']]]);
if ($this->localized === $this->model->getRegionPropertyName()) {
return;
}
echo $this->form->field($this->model, $this->model->getCityPropertyName())->widget(DepDrop::className(), ['options' => ['id' => 'location_city_id', 'cityholder' => Yii::t('common/geo/city', 'Select city')], 'data' => ArrayHelper::map(City::find()->where(['region_id' => $this->model->region_id])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), 'pluginOptions' => ['url' => Url::to(['/geo/city/list']), 'depends' => ['location_region_id']]]);
if ($this->localized === $this->model->getCityPropertyName()) {
return;
}
echo $this->form->field($this->model, 'address')->textInput();
}
示例15: field
/**
* 重写输入框
* @param type $model
* @param type $attribute
* @param type $options
* @return type
*/
public function field($model, $attribute, $options = array())
{
if (empty($options)) {
$options = ['template' => '{label}<div class="col-sm-5">{input}</div><div class="col-sm-5">{error}</div>', 'labelOptions' => ['class' => 'col-sm-2 control-label']];
}
return parent::field($model, $attribute, $options);
}