1

I'm using a <lightning-record-edit-form> with <lightning-input-field> children.

When required fields are not populated, it occurs the standard message "Complete this field".

What I want to do is to edit it with a custom message, but unfortunately it's not possible through the setCustomValidity() function (as the <lightning-input> has).

Is there another way to achieve this?

Thanks, Davide.

1 Answer 1

1

Custom Error Message On Input field

As workaround what you can do is set up a validation rule for that field and throw it field level so as to throw a custom error message.

In the below example I am throwing error at Email field of contact whenever I try to create one and my custom error message appears.

<lightning-record-edit-form object-api-name="Contact">
        <lightning-messages>
        </lightning-messages>
        <lightning-input-field field-name="Name">
        </lightning-input-field>
        <lightning-input-field field-name="Email">
        </lightning-input-field>
        <lightning-button class="slds-m-top_small" type="submit" label="Create new">
        </lightning-button>
    </lightning-record-edit-form>

validation Rule on contaact email field

2
  • Thanks for your response. This could help, I just have to understand how much effort could take to maintain it. Commented Feb 27, 2020 at 13:28
  • if it helps can u upvote. Commented Mar 4, 2020 at 5:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .