首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BootStrapValidator -在使用排除时不重置表单

BootStrapValidator -在使用排除时不重置表单
EN

Stack Overflow用户
提问于 2016-11-01 04:54:29
回答 1查看 369关注 0票数 1

我正在使用BootstrapValidator,我在重置表单时遇到了问题。当我在排除列表中添加“:隐藏”(我有隐藏的字段,当它们没有显示时,我需要跳过验证),表单将不会重置。我已经包括了图片和更多的文本如下:

代码语言:javascript
复制
 $('#frmLifecycleAddEdit').bootstrapValidator({
    framework: 'bootstrap',
    excluded: [':disabled', ':hidden'],
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
        txtStepName: {
            validators: {
                notEmpty: {
                    message: 'A valid step name is required.'
                }
            }
        },
        ddlCMCreateGroup: {
            validators: {
                notEmpty: {
                    message: 'CM creation group is required.'
                }
            }
        },
        ddlAssignGroup: {
            validators: {
                notEmpty: {
                    message: 'Assign group is required.'
                }
            }
        },
        ddlExpireGroup: {
            validators: {
                notEmpty: {
                    message: 'Expire group is required.'
                }
            }
        },
        txtDaysToExpire: {
            validators: {
                notEmpty: {
                    message: 'Expire days is required.'
                }
            }
        },
        txtStepNumber: {
            validators: {
                notEmpty: {
                    message: 'Step number is required.'
                }
            }
        }
    }
});

//View/Edit button click
$("#tblLifecycle tbody").on('click', 'button', function () {
    var oTable = $('#tblLifecycle').DataTable();
    var data = oTable.row($(this).parents("tr")).data();

    $('#frmLifecycleAddEdit').bootstrapValidator('resetForm', true);

    if ($('#ddlLifecycleName').val() == 'Accident') {
        $('#mtAddEditStep').text('Edit Accident Step');
        SetupEditAccident(data);
    } else {
        $('#mtAddEditStep').text('Edit Countermeasure Step');
        SetupEditCountermeasure(data);
    }
});

在单击按钮时,我正在尝试重置表单。

代码语言:javascript
复制
 $("#tblLifecycle tbody").on('click', 'button', function () {
    var oTable = $('#tblLifecycle').DataTable();
    var data = oTable.row($(this).parents("tr")).data();

    $('#frmLifecycleAddEdit').bootstrapValidator('resetForm', true);

    if ($('#ddlLifecycleName').val() == 'Accident') {
        $('#mtAddEditStep').text('Edit Accident Step');
        SetupEditAccident(data);
    } else {
        $('#mtAddEditStep').text('Edit Countermeasure Step');
        SetupEditCountermeasure(data);
    }
});

有人知道发生了什么吗?当我删除‘:隐藏’属性时,它可以工作,但是当所有字段都不存在时,我需要它来允许验证。

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-22 13:15:53

如果你没有显示控制,那么你就不能重置,所以你需要启用/禁用验证来解决这个难题。

把你的输入隐藏在第一位。将排除在外:“:禁用”在验证设置中,就好像您验证隐藏字段一样.

代码语言:javascript
复制
if (condition)
{            
    $("#mytextbox").css("display", "block");
    $('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', true);
} else 
{
    $("#mytextbox").css("display", "none");
    $('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', false);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40354367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档