• YII2 activeform样式修改


    <?php $form = ActiveForm::begin([
            'options'=>['enctype'=>'multipart/form-data','class' => 'form-horizontal'],
            'fieldConfig' => [  //统一修改字段的模板
                'template' => "{label}
    <div class="col-lg-5">{input}</div>
    <div class="col-lg-3">{error}</div>", 
            //修改显示内容默认为{label} {input} {hint} {error} 是html代码显示时的换行
    'labelOptions' => ['class' => 'col-lg-2 control-label'], //修改label的样式 ], ]);
    ?>
    //修改某字段的样式
    <?
    = $form->field($model, 'img_path',[ 'template' => "{label} <div class="col-lg-3">{input}</div> <div class="col-lg-2"><label for="uploadImg" class="btn btn-default forfocus1" onclick="changeImg(1,'forfocus');">选择图片<img src=""></label></div> {error}", 'labelOptions' => ['class' => 'col-lg-2 control-label'], ])->textInput(['maxlength' => 255,'placeholder'=>'专题图片','readonly'=>true])->label('专题名称')->hint('错误提示信息') ?>

    以下为一个完整的例子

    <?php $form = ActiveForm::begin([
            'options'=>['enctype'=>'multipart/form-data','class' => 'form-horizontal'],
            'fieldConfig' => [  
                'template' => "{label}
    <div class="col-lg-5">{input}</div>
    <div class="col-lg-5">{error}</div>",  
                'labelOptions' => ['class' => 'col-lg-2 control-label'],
            ],
        ]); ?>
        
        <?= $form->field($model, 'title')->textInput(['maxlength' => 255,'placeholder'=>'请输入专题名称'])->label('专题名称') ?>
        <?= $form->field($model, 'img_path',[  
                'template' => "{label}
    <div class="col-lg-3">{input}</div>
    <div class="col-lg-2"><label for="uploadImg" class="btn btn-default forfocus1" onclick="changeImg(1,'forfocus');">选择图片<img src=""></label></div>
    {error}",  
                'labelOptions' => ['class' => 'col-lg-2 control-label'],
            ])->textInput(['id'=>'img_path','maxlength' => 255,'placeholder'=>'专题图片','readonly'=>true])->label('专题名称') ?>
        <?= $form->field($model, 'showImg',[  
                'template' => "{label}
    <div id="showImg" class='col-lg-10'></div>",  
                'labelOptions' => ['class' => 'col-lg-2 control-label'],
            ])->label('图片预览') ?>
        <?= $form->field($model, 'link_to')->textInput(['maxlength' => 255,'placeholder'=>'请输入专题链接'])->label('专题链接') ?>
        </div>
            
        <div class="form-group" style="margin-left: 50px;">
            <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        </div>
    
        <?php ActiveForm::end(); ?>
  • 相关阅读:
    acm的STL容器之vector篇
    服务器远程管理方法及centos该装那个
    VB获取对象成员
    获取搜索引擎关键字建议
    IntelliJ IDEA乱码 问题
    排序算法思想
    ubuntu16 开机启动plank
    fail-fast出识
    html 标签过滤、转译、反转译
    (a ==1 && a== 2 && a==3) 有可能是 true 吗?
  • 原文地址:https://www.cnblogs.com/benlightning/p/4536392.html
Copyright © 2020-2023  润新知