3

I created a lightning component with lightning:recordEditForm and lightning:inputField to create a new record.

I have another field which I don't want it to be in the form but I want to populate it.

I didn't find a way to do this without put it in the form and use "slds-hidden" but that makes a gap in the UI.

Does someone know what to do in that case ? I mean, is there a better way to hide the field ? Or maybe a solution to "remove" the gap ?

Thanks.

3
  • 6
    Use slds-hide instead of slds-hidden. Commented Sep 2, 2018 at 12:45
  • Thanks ! slds-hide worked !!! I didn't event know it exists.
    – osos9
    Commented Sep 2, 2018 at 12:52
  • @itzmukeshy7, add your answer =P
    – glls
    Commented Sep 2, 2018 at 13:53

2 Answers 2

5

Use slds-hide instead of slds-hidden.

So the thing is if you just want to disappear the element from the UI then use the slds-hidden and it will take its space.

And to remove the space as well use the slds-hide.

0

To customize your form's behavior during loading or data submission, utilize the onload and onsubmit attributes to define event handlers. If you capture the submit event and submit the form programmatically, use event.preventDefault() to prevent the default event behavior, avoiding duplicate form submissions.

Although slds-hide can hide elements, I do not recommend using it because the element can still be inspected and its value seen. Additionally, it slows down the UI load since the element remains present in the HTML.

<lightning:recordEditForm
        objectApiName="Account"
        onsubmit ="{!c.handleSubmit}">
    <lightning:messages />
    <lightning:inputField aura:id="nameField" fieldName="Name"/>
    <lightning:button class="slds-m-top_small" type="submit" label="Create new" />
handleSubmit(event){
   event.preventDefault();       // stop the form from submitting
   const fields = event.detail.fields;
   fields.Street = '32 Prince Street';
   this.template.querySelector('lightning-record-edit-form').submit(fields);
}

You must log in to answer this question.

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