I have a Lightning RecordEditForm on a page that I'd like use multiple times. After a successful submit I want to clear the user's entries to allow the form to be reused. I have been unsuccessful at clearing RecordEditForm InputField component values in the onsuccess callback of the form.
Here is what I am trying:
Component
<lightning:recordEditForm aura:id="createAccount"
objectApiName="Account"
onsuccess="{!c.saveComplete}">
<lightning:messages />
<lightning:inputField fieldName="Name"
aura:id="accountNameField" />
<lightning:button aura:id="submit"
variant="brand"
type="submit"
label="Create Account"
class="slds-m-top_medium" />
</lightning:recordEditForm>
Controller
saveComplete: function (component, event, helper) {
helper.getAccountList(component);
// Grab inputField needing to be reset. Attempt to change it.
var cmp = component.find("accountNameField");
console.log("current value: " + cmp.get("v.value")); // Display current value
cmp.set("v.value", "a new value"); // Change it (hopefully)
console.log("new value: " + cmp.get("v.value")); // Display updated value
},
Console output
current value: cccc
new value: cccc
The user's inputed value does not change on the screen nor in the inputfield component attribute.
What is the proper way to reset a recordeditform inputfield after a submit completes?
Best Answer
I guess you can add your lightning:recordEditForm inside the aura:if and reset the flag variable used in aura:if in insaveComplete() method .This will refresh the form.