【问题标题】:jQuery Validate are hiding inputsjQuery Validate 隐藏输入
【发布时间】:2016-12-13 16:54:11
【问题描述】:

我正在尝试使用 jQuery Validate 验证一个简短的表单

这是我的功能:

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

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

这是我的表格:

<?= 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()?>

当我尝试进行验证时将字段留空,输入隐藏我不知道为什么,我无法弄清楚我的错误。

你们能帮帮我吗?

提前致谢

这些是表单的图像以及当字段为空时点击按钮时隐藏的输入

JsFiddle:My JsFiddle

【问题讨论】:

  • 隐藏是什么意思?你能创建一个 JSFiddle 吗?

标签: javascript jquery codeigniter validation


【解决方案1】:

如果你的脚本是正确的,那么替换视图文件如下:

<? 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();?>

【讨论】:

  • 你是否在控制器中加载了form helper
  • $autoload['helper'] = array('url', 'form');
  • 而不是使用自动加载。将其加载到控制器的构造函数$this-&gt;load-&gt;helper('form'); 希望它工作正常。
【解决方案2】:

感谢大家,我已经找到了原因:

我不知道为什么,但删除

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

包含表单的输入和标签使得一切都像一个魅力

【讨论】:

    猜你喜欢
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 2018-06-21
    相关资源
    最近更新 更多