2

I'm trying to do some custom validation on submit for a Lightning Web Component. I'm trying to use the setErrors method for a lightning-input-field (https://developer.salesforce.com/docs/component-library/bundle/lightning-input-field/specification) and nothing seems to be happening.

Does anyone have any examples of how I can get the error message to show or know where I can find one?

handleSubmit(events){
    let f = this.template.querySelector('.myInputField');
    f.setErrors('error message');
    f.reportValidity();
}
0

2 Answers 2

1

The description for the method setErrors on lightning-input-field mentions:

Reserved for internal use.

I would imagine we cannot use any such attribute/method if it is reserved for internal use.

2
  • You are correct, I just missed that part when I was reading it.
    – aaron
    Apr 18, 2019 at 17:57
  • @aaron It’s really easy to miss. I figured it out only when came across your question :)
    – Jayant Das
    Apr 18, 2019 at 22:56
0

You may want to use 'reportValidity()' of input-field. It should allow you to show error message if input is invalid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.