Включить кнопку отправки в валидаторе Bootstrap
Я использую валидатор Bootstrap, и у меня проблема в том, что я хочу включить кнопку отправки после того, как все значения верны, но не в состоянии это сделать.
$(document).ready(function() {
$('#ans_frm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
submitButtons: 'button[type="submit"]',
fields: {
ans: {
group: '.col-md-8',
validators: {
stringLength: {
min: 3,
max: 100,
message: 'The answer must be more than 2 and less than 100 characters long'
},
notEmpty: {
message: 'The answer must not be empty'
}
}
}
}
}).on('status.field.bv', function(e, data) {
disableSubmitButtons(false);
}
});
});
2 ответа
Вам необходимо отключить кнопку отправки .on('error.field.bv')
и включите его снова .on('status.field.bv')
,
И вы должны использовать data.bv.disableSubmitButtons()
метод!
Вы можете попробовать это?
$(document).ready(function() {
$('#ans_frm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
submitButtons: 'button[type="submit"]',
fields: {
ans: {
group: '.col-md-8',
validators: {
stringLength: {
min: 3,
max: 100,
message: 'The answer must be more than 2 and less than 100 characters long'
},
notEmpty: {
message: 'The answer must not be empty'
}
}
}
}
}).on('error.field.bv', function(e, data) {
data.bv.disableSubmitButtons(true); // disable submit buttons on errors
}
}).on('status.field.bv', function(e, data) {
data.bv.disableSubmitButtons(false); // enable submit buttons on valid
}
});
});
Использовать этот
$('#ans_frm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
live: 'enabled',
trigger: null
}).on('success.form.bv', function (e) {
// Prevent submit form
// e.preventDefault();
})
.on('error.form.bv', function () {
});