I have a lightning input field and I want to set the default value as 0 when the Lightning component is loading,

<lightning:input type="number" aura:id="coiId" label="Change Order $ impact" required="true" value="{!v.newRR.Change_Order_impact__c}"/>

I tried below two scenarios, but nothing work for me.

  1. Set the default value when defining the aura attribute

    <aura:attribute name="newRR" type="Case" default="{'sObjectType':'Case', 'Change_Order_impact__c':'0'}"/>

  2. Set the default value at doInit method in the controller.js


Can somebody show me the correct way to display default value as 0 when component is loading? Thanks...!

  • 1
    try to update the input value directly in doInit: component.find('coiId').set('v.value', 0); – itzmukeshy7 Apr 28 at 13:49
  • Thanks @itzmukeshy7 - This works. Actually component.set("v.newRR.Change_Order_impact__c",0); also works fine. But in my case, input field is hidden at page load. So I had to put either of above code at the controller method where input field makes visible. – Sudh Apr 28 at 16:36

Your Answer

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

Browse other questions tagged or ask your own question.