function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rama_SFDCRama_SFDC 

How to set default value to lightning:input in lightning

Hi All ,
is it possible to set  default value on lightning:input ?
below code : dafault attribute   not supporting 
<aura:attribute name="setdefaultval" type="String"/>
<lightning:input name="input8" value="{!v.ContactInstance.firstname}"  dafault ="{!v.setdefaultval}" />
Alain CabonAlain Cabon
Hello,

The default is only text ( default ="0" or  default = "toto" )  
https://developer.salesforce.com/docs/component-library/bundle/lightning:input/documentation

Otherwise, you use the init event for dynamic values.

Invoking Actions on Component Initialization: Use the init event to initialize a component or fire an event after component construction but before rendering.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_init_handler.htm
 
Raj VakatiRaj Vakati
try this code
 
<aura:hanlder value="this" name="init" action="{!c.doInit}"/>
<aura:attribute name="setdefaultval" type="String"  default="inputDefaultvalu"/>

<lightning:input name="input8" value="{!v.ContactInstance.firstname}"  />
 
doInit:function( cmp ,event,helper){

// set the value to v.ContactInstance.firstname from the setdefaultvalattribute 

}

 
Rama_SFDCRama_SFDC
Thanks Alain Cabon and Raj V 

below code working for me 

doInit:function( cmp ,event,helper){ 
   component.set("v.ContactInstance.firstname" ,"testing");
}