我正在使用 Boost strap 4 和 bootstrap select jQuery 插件。
我试图将 FormValidation.io 与我的表单集成。我已经使用普通输入字段进行了所有工作,但无法弄清楚如何将其与选择字段集成。
我希望它是一个必填字段,并在做出选择后显示勾号图标。
我的 FormValidation.io 代码:
document.addEventListener('DOMContentLoaded', function(e) {
const mydropzone = document.getElementById('mydropzone');
const RoleIdField = jQuery(mydropzone.querySelector('[name="roleId"]'));
const fv = FormValidation.formValidation(mydropzone, {
fields: {
first_name: {
validators: {
notEmpty: {
message: 'First Name is required'
},
regexp: {
regexp: /^[a-zA-Z]+$/,
message: 'First Name can only consist of alphabetical characters'
}
}
},
last_name: {
validators: {
notEmpty: {
message: 'Last Name is required'
},
regexp: {
regexp: /^[a-zA-Z]+$/,
message: 'First Name can only consist of alphabetical characters'
}
}
},
roleId: {
validators: {
notEmpty: {
message: 'Please select a Role'
},
}
},
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap: new FormValidation.plugins.Bootstrap(),
submitButton: new FormValidation.plugins.SubmitButton(),
icon: new FormValidation.plugins.Icon({
valid: 'fa fa-check',
invalid: 'fa fa-times',
validating: 'fa fa-refresh'
}),
}
}
);
});
$('#roleId').on('changed.bs.select', function (e, clickedIndex, isSelected, previousValue) {
// Revalidate the color field when an option is chosen
fv.revalidateField('roelId');
});
我的表单 ID 是“mydropzone”,我的选择名称和 ID 是“roleId”
任何帮助表示赞赏。