【FastAdmin开发记录】表单开关控制字段显示

背景:发起活动时,有些字段不是每个活动都需要配置的,所以需要根据需要来进行配置

效果

在这里插入图片描述

方案

html代码

<div class="form-group">
    <label class="control-label col-xs-12 col-sm-2">{:__('分组开关')}:</label>
    <div class="col-xs-12 col-sm-8">
        <input  id="c-groupSwitch" name="row[groupSwitch]" type="hidden" value="{$row.groupSwitch}">
        <a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-groupSwitch" data-yes="1" data-no="0" >
            <i class="fa fa-toggle-on text-success {eq name="$row.groupSwitch" value="0"}fa-flip-horizontal text-gray{/eq} fa-2x"></i>
        </a>
    </div>
</div>

<div class="form-group" id="group" {eq name="$row.groupSwitch" value="0"}style="display:none;"{/eq}>
    <label class="control-label col-xs-12 col-sm-2">{:__('分组')}:</label>
    <div class="col-xs-12 col-sm-8">
        <input id="c-group" class="form-control" name="row[group]" type="number" value="{$row.group|htmlentities}">
    </div>
</div>

根据 $row.groupSwitch 的值来判断当前默认的开关状态和控制是否显示对应的字段
需要注意的是开关的样式是通过class:fa-flip-horizontal text-gray来决定的
然后通过change事件来修改显示隐藏

$(document).on("change", "#c-groupSwitch", function(){
    $("#group").toggle($("#c-groupSwitch").val() > 0);
});

参考官方文档-开关组件

  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值