0

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 ?

  • What is front_id, shouldn't it be front_id__c? – shmuels Dec 31 '18 at 2:27
0

In JavaScript, the attribute is a native object, not a String. Do not include the quotes.

   component.set("v.newLine",
     { sobjectType: "ligne__c",
       Quantit_en_jours__c: 0,
       Prix_journalier__c: 0,
       Sujet__c: "",
       front_id__c:  0
     });

Also, double-check your code for spelling and case sensitivity. I fixed one presumably missing "__c", but you're going to need to pay more attention to your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.