I have this lightning component that is a form for an object called newLine :
<aura:component >
<aura:registerEvent name="updateFacture" type="c:factureLinesUpdate"/>
<aura:attribute name="newLine" type="ligne__c"
default="{ 'sobjectType': 'ligne__c',
'front_id': 0,
'Quantit_en_jours__c': 0,
'Prix_journalier__c ': 0,
'Sujet__c': '',
}"/>
<lightning:input aura:id="factureform" label="Quantité en jour"
type="number"
step="0.5"
value="{!v.newLine.Quantit_en_jours__c}"
placeholder="ABC Co."/>
<lightning:input aura:id="factureform" label="Description"
value="{!v.newLine.Sujet__c}"
placeholder="ABC Co."/>
<lightning:input aura:id="factureform" label="Prix journalier"
type="number"
step="50"
value="{!v.newLine.Prix_journalier__c}"
placeholder="100"/>
<lightning:button label="Save Line"
class="slds-m-top--medium"
variant="brand"
onclick="{!c.saveLine}"/>
</aura:component>
When a newLine is saved, the controller action saveLine is called. This action should then resets the form after the line is saved :
({
saveLine : function(component, event, helper) {
var line = component.get("v.newLine");
console.log("in saveline :", line.Description__c);
var updateEvent = component.getEvent("updateFacture");
component.set("v.saved", "true")
updateEvent.setParams({ "line": line });
updateEvent.fire();
component.set("v.newLine", "{'sobjectType': 'ligne__c', 'Quantit_en_jours__c': 0, 'Prix_journalier__c ': 0,'Sujet__c': '', 'front_id': 0}");
}
})
The form is rightly resetted to original values but then it is no longer possible to change the form values. How do you correctly resets the object value ?
front_id
, shouldn't it befront_id__c
? – shmuels Dec 31 '18 at 2:27