HTMLFieldSetElement: phương thức setCustomValidity()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Phương thức setCustomValidity() của giao diện HTMLFieldSetElement đặt thông báo lỗi tùy chỉnh cho phần tử <fieldset>. Sử dụng chuỗi rỗng để cho biết phần tử không có lỗi tùy chỉnh.

Phần tử <fieldset> không phải là ứng viên cho xác thực ràng buộc. Phương thức reportValidity() sẽ không khiến thông báo lỗi tùy chỉnh được hiển thị cho người dùng, nhưng đặt thuộc tính customError của đối tượng ValidityState của phần tử thành true và thuộc tính valid thành false.

Cú pháp

js
setCustomValidity(string)

Tham số

string

Chuỗi chứa thông báo lỗi. Chuỗi rỗng sẽ xóa bỏ mọi lỗi tùy chỉnh.

Giá trị trả về

Không có (undefined).

Ví dụ

js
const errorFieldSet = document.getElementById("checkErrors");
const errors = issuesToReport();
if (errors) {
  errorFieldSet.setCustomValidity("Có một lỗi");
} else {
  errorFieldSet.setCustomValidity("");
}

Đặc tả kỹ thuật

Specification
HTML
# dom-cva-setcustomvalidity-dev

Tương thích trình duyệt

Xem thêm