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
Sanchi9Sanchi9 

Show default values in lightning input

Hey!

I want to show some default values in a lightning input field. How can I achieve this?
Best Answer chosen by Sanchi9
AbhinavAbhinav (Salesforce Developers) 
Hi Priya,

Suppose you have 

<aura:attribute name="setdefaultval" type="String"/>
<lightning:input name="input8" value="{!v.ContactInstance.firstname}"  dafault ="{!v.setdefaultval}" />


You can set default value in  init handler.

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

reference:
https://developer.salesforce.com/forums/?id=9060G0000005mEgQAI

If it helps Please mark it as best Answer.

Thanks!

 

All Answers

AbhinavAbhinav (Salesforce Developers) 
Hi Priya,

Suppose you have 

<aura:attribute name="setdefaultval" type="String"/>
<lightning:input name="input8" value="{!v.ContactInstance.firstname}"  dafault ="{!v.setdefaultval}" />


You can set default value in  init handler.

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

reference:
https://developer.salesforce.com/forums/?id=9060G0000005mEgQAI

If it helps Please mark it as best Answer.

Thanks!

 
This was selected as the best answer
CharuDuttCharuDutt
Hii Priya 
Try Below Code
LWC

<lightning-input value={Value} onchange={handleChange}></lightning-input>
<lightning-button label='Click Me' onclick={handleClick}></lightning-button>



Js

 Value='default value';

    handleChange(event){
        this.Value = event.target.value;
    }
    handleClick(){
        alert(this.Value);
    }


AURA

<aura:hanlder value="this" name="init" action="{!c.doInit}"/>
<aura:attribute name="setdefaultval" type="String"  />

<lightning:input name="input" value="{!v.Value}"  />

JS

doInit:function( cmp ,event,helper){ 
   cmp.set("v.Value" ,"testing Value");
}
Please Mark It As Best Answer If It HelpsThank You!
 
Suraj Tripathi 47Suraj Tripathi 47
Hi Priya,
Greetings!

You can implement this,
1. Create a Aura Attribute of type String set the default value what you want.
2. Create a Input Field and create value attribute in input tag.
3. Give the String attribute for value of the value tag attribute.

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi