0

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

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

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

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.