簡體   English   中英

BootStrapValidator - 使用排除時表單不重置

[英]BootStrapValidator - form not resetting when using excluded

我正在使用BootstrapValidator,我遇到了重置表單的問題。 當我在排除列表中放入“:hidden”時(我隱藏了我需要在未顯示時跳過驗證的字段),表單將不會重置。 我在下面提供了圖片和更多文字:

 $('#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);
    }
});

我想在按鈕單擊期間重置表單。

 $("#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);
    }
});

有誰知道發生了什么? 當我刪除':hidden'屬性時,它可以工作,但我需要它在那里,以便在所有字段都不存在時允許驗證。

提前致謝!

如果你沒有顯示控制權,那么你就無法重置,所以你需要啟用/禁用驗證來解決這個難題。

將您的輸入隱藏在第一位。 make exclude:驗證設置中的':disabled' ,就像驗證隱藏字段一樣...

if (condition)
{            
    $("#mytextbox").css("display", "block");
    $('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', true);
} else 
{
    $("#mytextbox").css("display", "none");
    $('#Form').data('bootstrapValidator').enableFieldValidators('mytextbox', false);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM