我有这个html显示错误消息
class CurrencyInputFormatter extends TextInputFormatter{
@override
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
// TODO: implement formatEditUpdate
if(newValue.selection.baseOffset == 0){
print(true);
return newValue;
}
double value = double.parse(newValue.text);
final formatter = new NumberFormat.currency();
String newText = formatter.format(value/100);
return newValue.copyWith(text: newText,
selection: new TextSelection.collapsed(offset: newText.length));
}
}
我在所有字段上都获得了Bootstrap验证,但我也希望将其添加到我的验证中。
<form id="order-form" class="needs-validation" method="post" enctype="multipart/form-data" novalidate>
<div id="quantity-zero" class="invalid-feedback"></div>
如果quantitySelected为false,我想通过引导错误将此添加到其中,以下给出了错误。
错误:TypeError:$(...)。form未定义
$("#previewBtn").click(function(event) {
var form = $("#order-form");
var quantitySelected = null;
$(".quantity-select").each(function () {
if($(this).val() > 0) {
quantitySelected = true;
return false;
} else {
quantitySelected = false;
//$("#quantity-zero").show();
}
})
我以此验证表格
if(quantitySelected === false) {
$("#quantity-zero").form.setCustomValidity('This is an error.');
}
如果 if (form[0].checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
} else {
$("#exampleModal").show();
}
form.addClass('was-validated');
});
为假,如何与我的其他Bootrap验证一起显示错误?