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);
}
slds-hide
instead ofslds-hidden
.