0

I'm creating some small lighting components for use with Quick Actions.

While "Never trust the client" means I will have backend validation, for a good user experience, I'd prefer to prevent bad data from even getting submitted.

The seems to a convenient choice for receiving input and getting it take forward data to my server is working beautifully.

However, it isn't clear whether or how I might do any sort of validation on this data.

Or, if if I use some other input elements for the UX, will I be able to use them with lightning:recordEditForm?

(This question is different from the possible duplicate because the actual text of the question seemed to be about conditionally modifying the form to include additional fields instead of about validation. And the provided answer was focused on the same goal. Reading comments, I was able to glean enough information, but it a badly titled question and not a true duplicate.)

  • 2
    The answer is Yes, you can do a client side validation using lightning:recordEditForm and lightning:inputField. You can find more details around implementation on this answer – Jayant Das Sep 12 '18 at 16:01
  • 1
    Cheers for the fast response! Will dig deeper tomorrow. :-) – Brian Kessler Sep 12 '18 at 16:13
  • Yes, I was able to learn what I needed to from the other question. At a very superficial level, it might even seem like a duplicate. However, the text of the question seemed to be asking something different and it was more from the threaded conversation that I pieced together the answer than from the actual accepted answer. – Brian Kessler Sep 13 '18 at 8:46
1

Thanks to the questionably titled "possible duplicate", pointed out by @Jayant Das, I was able to piece together a solution.

  1. My component need to interrupt the submit process. I was able to do this with:

    <lightning:recordEditForm objectApiName="Opportunity" 
      recordId="{!v.recordId}" onsubmit="{!c.sendRequest}" >
    
  2. Not strictly necessary, but for good UX, I needed some way to display the error, eg:

         <aura:attribute access="private" name="error" type="String" />
         <!--Details of this are unimportant-->
         <c:ErrorNoticeContainer error="{!v.error}" />
    
  3. I needed to get and check the parameter of interest:

    sendRequest: function  (component, event, helper) {
        event.preventDefault();
        const invoiceDiscountRate = event.getParam('fields').InvoiceDiscountRate__c;
        // Details of these methods are not so important as long as they do what the label on the tin suggests.
        if (helper.isValid(component, invoiceDiscountRate)) {
            helper.sendToServer(component, invoiceDiscountRate);
        }
    

    }

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