0

Resume of scenario: Whether a user does not select any value from the picklist the field should throw an error message.

<lightning:recordEditForm aura:id="raiseIssueForm"
                              recordTypeId="{!v.recordExample}"
                              objectApiName="Case"
                              recordId="{!v.valueExample}"
                              onload="{!c.onLoadIssue}"
                              onsubmit="{!c.onSubmitIssue}"
                              onsuccess="{!onSuccessfulRaiseIssueSubmission}"
                              onerror="{!c.onRaiseIssueSubmissionError}"
                              class="slds-card__body_inner">
    <div class="slds-form">
        <div class="slds-form-element slds-form-element_stacked slds-size_1-of-4">

            <label class="slds-form-element__label" for="issueType">{!$Label.c.example}</label>
            <div class="slds-form-element__control">
                <lightning:inputField aura:id="issueType"
                                      class="example__class"
                                      fieldName="Type"
                                      variant="label-hidden"
                                      required="true"
                                      value="{!v.selectedIssueType}"/>
            </div>
        </div>
    </div>
</lightning:recordEditForm>

Piece of code from my helper, the picklist loads with --None-- as usual, and whether I press submit the alert doesn't show anything, although if I change the value I can see it. So my question: How does it possible validating if it's empty instead to loop through all values checking if it's different for example?

var field = component.find("issueType").get("v.value");
     this.checkEmptyField(component, field);
      //just an example
     if(issueType != '--None--') {
         alert(issueType);
     }
4
  • have you considered using an 'onchange' event, and crosschecking the value ?
    – glls
    Apr 9, 2020 at 1:14
  • no, because I am trying to capture the first value without users change it (if they left not selected I mean)
    – Carlos
    Apr 9, 2020 at 8:43
  • so you are saying if "none" is already selected in "Type" picklist and then you click on submit it wont throw any error and will save your record?
    – User6670
    Apr 9, 2020 at 8:51
  • Technically there's nothing selected, as my alert shows empty and I couldn't pick up the value.
    – Carlos
    Apr 9, 2020 at 9:39

1 Answer 1

0

As I already had the value from the field itself, but no references (typeOf, instanceOf) using the exclamation mark (not) was possible validating.

if(!issueType) { code.. }

You must log in to answer this question.

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