Yii2 ActiveForm表单自定义样式
实例:
<?php $form = ActiveForm::begin([
'fieldConfig' => [
'template' => '<div class="col-lg-3 control-label color666 fontweight">{label}:</div>
<div class="col-lg-5" style="padding-left: 15px;padding-right: 15px;">{input}</div>
<div class="col-lg-4">{error}</div>',
'inputOptions' => ['class' => 'form-control'],
],
'options' => ['class' => 'form-horizontal t-margin20','id'=>'form1','enctype'=>"multipart/form-data"],
]);
//\app\helpers\Util::dump($form);
/*打印此处$form ActiveForm::begin([]) 追踪源码,调用父级的widget的begin方法是实例化ActiveForm This method creates an instance of the calling class
*/
?>
/*
自定义样式
$form->field()
调用该方法 查看源码 注释写的 options配置是 ActiveField These are properties of [[ActiveField]] 查看 ActiveField 的属性 就知道可以修改哪些样式
/**
* Generates a form field.
* A form field is associated with a model and an attribute. It contains a label, an input and an error message
* and use them to interact with end users to collect their inputs for the attribute.
* @param Model $model the data model
* @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
* about attribute expression.
* @param array $options the additional configurations for the field object. These are properties of [[ActiveField]]
* or a subclass, depending on the value of [[fieldClass]].
* @return ActiveField the created ActiveField object
* @see fieldConfig
*/
public function field($model, $attribute, $options = [])
{
$config = $this->fieldConfig;
if ($config instanceof \Closure) {
$config = call_user_func($config, $model, $attribute);
}
if (!isset($config['class'])) {
$config['class'] = $this->fieldClass;
}
return Yii::createObject(ArrayHelper::merge($config, $options, [
'model' => $model,
'attribute' => $attribute,
'form' => $this,
]));
}
*/ <?=$form->field($model, 'product_name',['labelOptions' => ['class' => 't-r-pd5'],'options'=>['class'=>'']])->textInput()?>
ActiveField 部分代码:
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/ namespace yii\widgets; use Yii;
use yii\base\Component;
use yii\base\ErrorHandler;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\base\Model;
use yii\web\JsExpression; /**
* ActiveField represents a form input field within an [[ActiveForm]].
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ActiveField extends Component
{
/**
* @var ActiveForm the form that this field is associated with.
*/
public $form;
/**
* @var Model the data model that this field is associated with
*/
public $model;
/**
* @var string the model attribute that this field is associated with
*/
public $attribute;
/**
* @var array the HTML attributes (name-value pairs) for the field container tag.
* The values will be HTML-encoded using [[Html::encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* The following special options are recognized:
*
* - tag: the tag name of the container element. Defaults to "div".
*
* If you set a custom `id` for the container element, you may need to adjust the [[$selectors]] accordingly.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = ['class' => 'form-group'];
/**
* @var string the template that is used to arrange the label, the input field, the error message and the hint text.
* The following tokens will be replaced when [[render()]] is called: `{label}`, `{input}`, `{error}` and `{hint}`.
*/
public $template = "{label}\n{input}\n{hint}\n{error}";
/**
* @var array the default options for the input tags. The parameter passed to individual input methods
* (e.g. [[textInput()]]) will be merged with this property when rendering the input tag.
*
* If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $inputOptions = ['class' => 'form-control'];
/**
* @var array the default options for the error tags. The parameter passed to [[error()]] will be
* merged with this property when rendering the error tag.
* The following special options are recognized:
*
* - tag: the tag name of the container element. Defaults to "div".
* - encode: whether to encode the error output. Defaults to true.
*
* If you set a custom `id` for the error element, you may need to adjust the [[$selectors]] accordingly.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $errorOptions = ['class' => 'help-block'];
/**
* @var array the default options for the label tags. The parameter passed to [[label()]] will be
* merged with this property when rendering the label tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $labelOptions = ['class' => 'control-label'];
/**
* @var array the default options for the hint tags. The parameter passed to [[hint()]] will be
* merged with this property when rendering the hint tag.
* The following special options are recognized:
*
* - tag: the tag name of the container element. Defaults to "div".
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $hintOptions = ['class' => 'hint-block'];
/**
* @var boolean whether to enable client-side data validation.
* If not set, it will take the value of [[ActiveForm::enableClientValidation]].
*/
public $enableClientValidation;
/**
* @var boolean whether to enable AJAX-based data validation.
* If not set, it will take the value of [[ActiveForm::enableAjaxValidation]].
*/
public $enableAjaxValidation;
/**
* @var boolean whether to perform validation when the value of the input field is changed.
* If not set, it will take the value of [[ActiveForm::validateOnChange]].
*/
public $validateOnChange;
/**
* @var boolean whether to perform validation when the input field loses focus.
* If not set, it will take the value of [[ActiveForm::validateOnBlur]].
*/
public $validateOnBlur;
/**
* @var boolean whether to perform validation while the user is typing in the input field.
* If not set, it will take the value of [[ActiveForm::validateOnType]].
* @see validationDelay
*/
public $validateOnType;
/**
* @var integer number of milliseconds that the validation should be delayed when the user types in the field
* and [[validateOnType]] is set true.
* If not set, it will take the value of [[ActiveForm::validationDelay]].
*/
public $validationDelay;
/**
* @var array the jQuery selectors for selecting the container, input and error tags.
* The array keys should be "container", "input", and/or "error", and the array values
* are the corresponding selectors. For example, `['input' => '#my-input']`.
*
* The container selector is used under the context of the form, while the input and the error
* selectors are used under the context of the container.
*
* You normally do not need to set this property as the default selectors should work well for most cases.
*/
public $selectors = [];
/**
* @var array different parts of the field (e.g. input, label). This will be used together with
* [[template]] to generate the final field HTML code. The keys are the token names in [[template]],
* while the values are the corresponding HTML code. Valid tokens include `{input}`, `{label}` and `{error}`.
* Note that you normally don't need to access this property directly as
* it is maintained by various methods of this class.
*/
public $parts = [];
Yii2 ActiveForm表单自定义样式的更多相关文章
- [moka同学笔记]yii2 activeForm 表单样式的修改(二)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABAEAAANXCAIAAADLkdErAAAgAElEQVR4nOzdfWwc953nef6zwO5Zg8
- [moka同学笔记]yii2 activeForm 表单样式的修改
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAv4AAANcCAIAAACopDy/AAAgAElEQVR4nOzdfXAb52H4ef1veSatRV
- [YII2] Activeform表单部分组件使用方法
文本框:textInput(); 密码框:passwordInput(); 单选框:radio(),radioList(); 复选框:checkbox(),checkboxList(); 下拉框:dr ...
- yii中调整ActiveForm表单样式
Yii2中对于表单和字段的支持组件为ActiveForm和ActiveField, <?php $form = ActiveForm::begin([ 'id' => 'login-for ...
- yii2 创建ActiveForm(表单)
表单的生成表单中的方法 ActiveForm::begin()方法 ActiveForm::end()方法 getClientOptions()方法 其它方法:errorSum ...
- YII2.0使用ActiveForm表单(转)
Controller控制器层代码 <?php namespace frontend\controllers; use frontend\models\UserForm; class UserCo ...
- yii2之ActiveForm表单使用
因目前项目并非前后端分离模式,且用到PHP的yii2框架(所有html代码,js较多内嵌在.php文件内多少采用同步提交[喷墨中...]),遂对于前端面上需要用到的yii2小组件一些整理(因是前端若涉 ...
- css修改input表单默认样式重置与自定义大全
链接地址: 伪元素表单控件默认样式重置与自定义大全 http://www.zhangxinxu.com/wordpress/?p=3381 Chrome 现在不支持通过伪元素修改 meter 元素样式 ...
- [moka同学笔记]yii2.0表单的使用
1.创建model /biaodan.php <?php /** * Created by PhpStorm. * User: moka同学 * Date: 2016/08/05 * Tim ...
随机推荐
- TDirectory.GetParent获取指定目录的父目录
使用函数: System.IOUtils.TDirectory.GetParent class function GetParent(const Path: string): string; stat ...
- An easy way to syncTime using C#
/* * Created by SharpDevelop. * User: Administrator * Date: 2013/10/23 * Time: 8:57 * author zibet * ...
- Core Animation
position和anchorPoint的区别 -整理自苹果官方文档- Layers使用两种坐标系: 1. point-based :1)当需要定义layer在屏幕中或是距另一个layer的位置时 ...
- 介绍.NET Core
在connect (),我们宣布.NET 核心将能完全释放,作为开放源码软件.我也答应在.NET 核心跟更多的细节.在这篇文章,我将提供.NET 核心,我们如何去释放它,它涉及到.NET 框架,如何和 ...
- Centos开启FTP及用户配置
vsftpd作为FTP服务器,在Linux系统中是非常常用的.下面我们介绍如何在centos系统上安装vsftp. 什么是vsftpd vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序 ...
- Maven构建灵活配置文件
本文解决以下问题: Maven下面启动Main函数: 配置JDK版本 如何配置文件,在开发部署测试各个不同版本间无缝切换配置文件: 启动Main函数 Maven默认是不支持Main函数程序,需要在po ...
- Android的那些轮子
整个AOSP代码,包天包地,从kernel,libc,gui,net……简直包括了绝大多普通程序员职业生涯涉及的整个领域.其实,开源界早已经遇到并且解决了Android的很多问题,不过google讨厌 ...
- 17.1.1 How to Set Up Replication 设置复制:
17.1.1 How to Set Up Replication 设置复制: 17.1.1.1 Setting the Replication Master Configuration 17.1.1. ...
- 替换SQL Server字段中的换行符,回车符
replace(string_expression , string_pattern , string_replacement) 第一个参数:要查找的字段. 第二个参数:要查找的字符. 第三个参数:要 ...
- ELK之topbeat部署
topbeat定期收集系统信息如每个进程信息.负载.内存.磁盘等等,然后将数据发送到elasticsearch进行索引,最后通过kibana进行展示. 下面是具体的安装及配置步骤: 1.安装topbe ...