開発者は、lightning-record-edit-form を使用してリードに関する情報を収集する Lightning Web コンポーネントを作成しました。ユーザーは、潜在顧客レコードを保存しようとすると、入力に関するエラー メッセージが一度に 1 つしか表示されないと不満を抱いています。
JavaScript の介入を最小限に抑えながら、複数のフィールドで検証を実行し、複数のエラー メッセージを同時に表示するための推奨されるアプローチは何ですか?
正解:B
The recommended approach to perform validations on more than one field, and display multiple error messages simultaneously with minimal JavaScript intervention is to use an external JavaScript library. An external JavaScript library is a collection of reusable code that can provide additional functionality and features to the Lightning web component. The developer can use an external JavaScript library that supports form validation, such as jQuery Validation or Parsley.js, and import it into the Lightning web component. The developer can then use the library's methods and options to define the validation rules and messages for each field, and to display the errors on the component. Using a try/catch/finally block will not help, as it is used to handle exceptions and errors in the code, but it does not perform validations on the fields or display error messages. Using validation rules will not help, as they are used to enforce data quality and integrity on the server side, but they do not perform validations on the client side or display error messages on the component. Using an Apex trigger will not help, as it is used to execute logic before or after a record is inserted, updated, deleted, or undeleted, but it does not perform validations on the client side or display error messages on the component. Reference: [Use Third-Party JavaScript Libraries], [Lightning Web Components Developer Guide]