#bootstrapvalide使用案例#

验证数据提供参考

$("#goodsForm").bootstrapValidator({
         message: 'This value is not valid',
         feedbackIcons: {
             valid: 'glyphicon',
             invalid: 'glyphicon',
             validating: 'glyphicon'
         },
         fields: {
             goods_code: {
                 validators:
                     {
                         notEmpty: {
                             message: __("产品编号不能为空")
                         },
                         regexp: {
                             regexp: /^[\w\s]+$/,
                             message: __("产品编号只能为字母和数字")
                         },
                         stringLength: {
                             min: 2,
                             max: 50,
                             message: __('产品编号长度为2~50位')
                         }
                     }
             },
             goods_name: {
                 validators:
                     {
                         notEmpty: {
                             message: __("产品名称不能为空")
                         }/* ,
                         stringLength: {
                             min: 1,
                             max: 20,
                             message: __('产品名称长度为1~20位')
                         } */
                     }
             },
             goods_price: {
                 validators:
                     {
                         notEmpty: {
                             message: __("零售价格不能为空")
                         },
                         regexp: {
                             regexp: /^(0(?:[.](?:[0-9]\d?|0[0-9]))|[0-9]\d*(?:[.]\d{1,2}|$))$/,
                             message: __('请输入数字并且小数点后2位')
                         },
                         between:
                         {
                             min: 0,
                             max: sysParameter.unit_price*10000,
                             message: __('零售价格最低为0且不能超过') + sysParameter.unit_price + __('万')
                         }
                     }
             },
             goods_cost: {
                 validators:
                     {
                         regexp: {
                             regexp: /^(0(?:[.](?:[0-9]\d?|0[0-9]))|[0-9]\d*(?:[.]\d{1,2}|$))$/,
                             message: __('请输入数字并且小数点后2位')
                         },
                         between:
                         {
                             min: 0,
                             max: sysParameter.unit_price * 10000,
                             message: __('参考进价最低为0且不能超过' )+ sysParameter.unit_price+ __('万')
                         }
                     }
             },
             goods_vip_price: {
                 validators:
                     {
                         regexp: {
                             regexp: /^(0(?:[.](?:[0-9]\d?|0[0-9]))|[0-9]\d*(?:[.]\d{1,2}|$))$/,
                             message: __('请输入数字并且小数点后2位')
                         },
                         between:
                         {
                             min: 0,
                             max: sysParameter.unit_price * 10000,
                             message: __('产品会员价最低为0且不能超过') + sysParameter.unit_price+ __('万')
                         }
                     }
             },
             goods_stock: {
                 validators:
                     {
                         notEmpty: {
                             message: __("库存不能为空")
                         },
                         regexp: {
               min: 1,
                             regexp: /^[0-9]*[1-9][0-9]*$/,
               message: __('请输入正整数')
                         }
                     }
             }
         }
     }).on("success.form.bv", function (e) {
         e.preventDefault();
         var isSubmit = true;
         var data = $("#goodsForm").serializeObject();
         var isSubmit = true;
         if ($("#goods_code").val() == "") {
             alertError(__("产品编号不能输入为空"));
             isSubmit = false;
             return;
         }

         //是否积分
         if ($("#is_points").prop("class") == "active") 
{
             data.goods_is_points = 1;
         }
         else {
             data.goods_is_points = 0;
         }
         
//是否折扣
         if ($("#is_discount").prop("class") == "active") 
{
             data.goods_is_discount = 1;
         }
         else {
             data.goods_is_discount = 0;
         }

         //验证积分
         isSubmit = obj.changeFun(1);
         if (!isSubmit) {
             if (data.goods_is_points == 0) 
   {
                 return false;
             }
         }

         //验证折扣
         isSubmit = obj.changeFun(2);
         if (!isSubmit) {
             if (data.goods_is_discount == 0) 
   {
                 return false;
             }
         }

         if ($("#goods_cat").val() == null) 
{
             alertError(__("请先添加产品类别"));
             isSubmit = false;
             return;
         }

         if (isSubmit) 
{             
             if (($("#is_discount").prop("class") == "active") && $("#goods_vip_price").val() > 0) {                   
      alertError(__("【产品会员价】和【最低折扣】,只允许选择一种折扣方式,请重新输入!"));
             }else 
   {
      if(goods_id)
      {
         var url = SYS.CONFIG.index_url + '?ctl=Goods_Base&met=edit&typ=json';
         data.goods_id = goods_id;
      }else{
         var url = SYS.CONFIG.index_url + '?ctl=Goods_Base&met=add&typ=json';
      }
      
                 $.ajax({
         url: url,
         type: 'post',
         data: data,
         dataType: "json",
         success: function (data) 
         {
            if (data && data.status == 200) 
            {
               alertMessage(__("操作成功"));
               setTimeout(function () 
               {
                  window.location.href = SYS.CONFIG.index_url + '?ctl=Goods_Base&met=index&typ=e';
               }, 1000);
            
            } else {
               alertError(data.msg);
            }
         }
      });
             }
         }
     });
 },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值