ElementInternals: willValidate property
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2023.
Thuộc tính chỉ đọc willValidate của giao diện ElementInternals trả về true nếu phần tử là phần tử có thể gửi và là ứng viên cho xác thực ràng buộc.
Các phần tử bị loại khỏi danh sách ứng viên xác thực ràng buộc bao gồm các phần tử có thuộc tính: disabled, hidden hoặc readonly, các phần tử input có type=button hoặc type=reset, hoặc bất kỳ phần tử nào là phần tử <datalist> hoặc có phần tử tổ tiên <datalist>.
Giá trị
true nếu phần tử là ứng viên xác thực ràng buộc, ngược lại là false.
Ngoại lệ
NotSupportedErrorDOMException-
Được ném ra nếu phần tử không có thuộc tính
formAssociatedđược đặt thànhtrue.
Ví dụ
Ví dụ sau hiển thị một thành phần hộp kiểm tùy chỉnh với formAssociated được đặt thành true, giá trị của willValidate được ghi ra console.
class CustomCheckbox extends HTMLElement {
static formAssociated = true;
constructor() {
super();
this.internals_ = this.attachInternals();
}
// …
}
window.customElements.define("custom-checkbox", CustomCheckbox);
let element = document.getElementById("custom-checkbox");
console.log(element.internals_.willValidate); // true
Thông số kỹ thuật
| Specification |
|---|
| HTML> # dom-elementinternals-willvalidate> |