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

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

The default is only text ( default ="0" or  default = "toto" )

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.
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 


Thanks Alain Cabon and Raj V 

below code working for me 

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