简体   繁体   中英

BootStrapValidator - form not resetting when using excluded

I am using BootstrapValidator and I'm having an issue with resetting the form. When I put ":hidden" in the excluded list (I have fields that are hidden that I need to skip validation on when they are not showing) the form will not reset. I have included images and more text below:

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

I am trying to reset the form during the 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);
    }
});

Does anyone know what is happening? When I remove the ':hidden' attribute it works, but I need it in there to allow validation when all fields are not present.

Thanks in advance!

if you dont show control , then you cant reset, so you need to enable/disable validation to solve this dilemma.

make your input hidden in first place. make excluded: ':disabled' in validation settings, as if you validate hidden fields...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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