【问题标题】:jQuery validator of radio input groups is not validating in Bootstrap无线电输入组的 jQuery 验证器未在 Bootstrap 中验证
【发布时间】:2014-05-13 16:07:54
【问题描述】:

我正在开发一个需要使用 jQuery 验证器插件进行单选单选按钮验证的项目。我制作了一个完美运行的示例,并将其实现到实际项目的代码中,现在即使该示例完美运行,它也完全拒绝工作。有点气人。除了引导元素之外,此代码与示例中的代码相同。

这里的JSFiddle:http://jsfiddle.net/3vwWL/

<form action="" id="contact-form" class="form-horizontal">
   <form action="" id="registration-form">
      <div class="col-md-6">
         <div class = "form-group">
            <label class = "control-label">Must choose one</label>
            <br />
            <input name="radio" type="radio" data-validation="required" value="1" />A
            <input name="radio" type="radio" value="1" />B 
            <input name="radio" type="radio" value="1" >C 
            <input name="radio" type="radio" value="1" />D
         </div>
      </div>
   </form>
</form>

JS:

$.validate({
    form: "#contact-form, registration-form",
    modules: 'location, date, security, file',
    onModulesLoaded: function () {
        $('#country').suggestCountry();
    },
    onError: function () {
        alert("You've missed something");
    },
    onSuccess: function () {
        alert("All clear!");
        return false;
    }
});

$('input')
    .on('beforeValidation', function () {
    console.log('About to validate input "' + this.name + '"');
}).on('validation', function (evt, isValid) {
    var validationResult = '';
    if (isValid === null) {
        validationResult = 'not validated';
    } else if (isValid) {
        validationResult = 'VALID';
    } else {
        validationResult = 'INVALID';
    }
    console.log('Input ' + this.name + ' is ' + validationResult);
});

// Restrict presentation length
$('#presentation').restrictLength($('#pres-max-length'));

所有其他表单验证都有效,但不是这个。

【问题讨论】:

    标签: jquery twitter-bootstrap validation radio


    【解决方案1】:

    html错了,你应该用一个表格,其他表格里面的表格不行,

    试试这个,

    <form action="" id="contact-form" class="form-horizontal">
        <div class="col-md-6">
          <div class = "form-group">
             <label class = "control-label">Must choose one</label>
             <br />
             <input name="radio" type="radio" data-validation="required" value="1" />A        
             <input name="radio" type="radio" value="1" />B  
             <input name="radio" type="radio" value="1" />C
             <input name="radio" type="radio" value="1" />D
          </div>
        </div>
    </form>
    

    现在只验证#contact-form

    【讨论】:

    • 删除多余的表单并仅验证 #contact-form 不幸的是没有做任何事情:'(
    猜你喜欢
    • 2018-07-20
    • 2017-04-06
    • 1970-01-01
    • 2010-12-19
    • 2016-12-23
    • 2012-11-14
    • 2014-11-02
    • 2019-12-01
    • 1970-01-01
    相关资源
    最近更新 更多