1

When you submit a lightning-record-edit-form it checks the lightning-input fields against any Validation Rules on those fields and displays the corresponding error message if the rule isn't met, which is great. It then saves that record. What I would like to do is perform the validation check and show the error message BUT - if it passes the error check, do NOT save the record. Does anyone know if this is possible?

I'm using a custom submit handler but if I prevent the default via event.preventDefault(); it doesn't perform the validation. So the submit action has to take place

2
  • 1
    I think you will have to build the checks that are happening on the server on the UI yourself. The validation checks take place when the record is submitted so, the validation and submission are not two different transactions, it is in fact a single transaction with two process happening one after the other based on order of execution rules. If you want to validate only, then you will need to build those rules in the UI yourself. – manjit5190 Mar 5 '20 at 13:30
  • Thanks @manjit5190 - I think you're right. I suspected as much as if it were possible to validate separately to submitting you'd expect to find something on that in the documentation. Ah well! – LouisSkelton Mar 5 '20 at 14:00
0

You could make a call to the server, try to save the record and if it is successfully saved, rollback the transaction using Database.rollback() and Database.setSavepoint(). If it is not, you could return the error message.

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.