如何验证隐藏字段

时间:2014-08-07 12:44:31

标签: validation

我使用bootstrapValidator插件并有一个隐藏字段,其值是动态设置的。当用户做出添加到隐藏字段的选项时,验证不会将其提取。

以下是我试图验证的字段 customerVehicles HTML代码:

<div class="form-group">
  <label  class="" for="fname"></label>   
  <input type="hidden" name="customerVehicles" class="customerVehicles form-control"  id="customerVehicles"   />   
</div><!-- close form group -->

这是我的验证块 代码:

$('#step2').bootstrapValidator({
   message: 'This value is not valid',
   live: 'enabled',
   feedbackIcons: {
   valid: 'glyphicon glyphicon-ok',
   invalid: 'glyphicon glyphicon-remove',
   validating: 'glyphicon glyphicon-refresh'
  },
  submitHandler: function(validator, form, submitButton) {

  document.getElementById("next2").disabled=true;

  $.ajax({
    type: "POST",
    url: "scripts/process-step2.php",
    data: $('#step2').serialize(),
    success: function(msg){

           ...
    },
    error: function(){
      alert("error");
    }
   });//close ajax
  },
  excluded: ':disabled',
  fields: {

      customerVehicles: {
          message: 'Please Make a Selection',
          validators: {
          notEmpty: {
              message: 'Please Make a Selection'
          }    
        }
      }// end dropdown
   } // end field
});// bootstrapValidator

1 个答案:

答案 0 :(得分:1)

我知道这是旧的,但这对我有用。被排除的选项看起来是一个状态数组。尝试:

excluded: [':disabled']