简体   繁体   English

jQuery Validate隐藏输入

[英]jQuery Validate are hiding inputs

I'm trying to validate a short form with jQuery Validate 我正在尝试使用jQuery Validate验证简短形式

this is my function: 这是我的功能:

$('#add').click(function(){
    $('#addForm').validate({
        rules: {
            "nombre": {
                required: true
            },
            "cajas": {
                required: true
            },
        },

        messages: {
            "nombre": "Campo obligatorio",
            "cajas": "Campo Obligatorio",
        }
    });
});

and this is my form: 这是我的表格:

<?= form_open('Sucursales/agregarSucursal', 'class="form-inline targen text-center" id="addForm"') ?>
        <div class="form-group">
            <label>Nombre: </label>
            <input type="text" name="nombre" id="nombre" class="form-control">
        </div>
        <div class="form-group">
            <label>Número de Cajas: </label>
            <input type="text" name="cajas" id="cajas" class="form-control">
        </div>
        <div class="form-group">
            <button class="btn btn-inverse btnInline" id="add">Agregar</button>
        </div>
<?=form_close()?>

When i try to make the validation leaving the fields empty, the input is hidding i don't know why and i can't figure my error. 当我尝试进行验证时,将字段留空时,输入隐藏,我不知道为什么,我也无法弄清楚我的错误。

Can you help me guys? 你能帮我吗?

Thanks in advance 提前致谢

These are the images of the form and the hidden inputs when you hit the button when the fields are empty 这些是表单的图像以及在字段为空时单击按钮时的隐藏输入

从正常

隐藏的输入

JsFiddle: My JsFiddle JsFiddle: 我的JsFiddle

If your script is correct.Then replace view file as follows: 如果脚本正确,则按如下所示替换视图文件:

<? echo form_open('Sucursales/agregarSucursal', array('class'=>'form-inline targen text-center', 'id'=>'addForm')); ?>
        <div class="form-group">
            <label>Nombre: </label>
            <input type="text" name="nombre" id="nombre" class="form-control">
        </div>
        <div class="form-group">
            <label>Número de Cajas: </label>
            <input type="text" name="cajas" id="cajas" class="form-control">
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-inverse btnInline" id="add">Agregar</button>
        </div>
<? echo form_close();?>

Thanks to all guys, i already found the cause of this: 感谢所有人,我已经找到了造成这种情况的原因:

I don't know why but removing 我不知道为什么,但删除

<div class="form-group"></div>

That contains the input and label of the form makes that all works like a charm 包含表单的输入和标签,使所有内容都像魅力一样

现在正在工作:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM