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
Matt Prorok 7Matt Prorok 7 

Can you put a default/starting value on a lightning:input tag?

Hi everyone,

I'm new to lightning development and was just wondering about the following use case. I want to create a lightning component that allows end users to input data using the lightning:input tag, but I don't see a way to set a default value that is editable. Does anyone know whether this is possible and how to do it?

Thanks!

-Matt
Rajiv Penagonda 12Rajiv Penagonda 12
Matt, I believe the element supports the "value" attribute which accepts merge fields. See if the below code works
<aura:attribute name="checkboxFieldValue" type="Boolean" default="true" />
<lightning:input type="checkbox" label="Blue" name="blue" value="{!v.checkboxFieldValue}" />
The attributes "type" and "default" of the aura:attribute "checkboxFieldValue" will change based on the type of the lightning:input element you choose to use.

Hope this helps.
-Rajiv
Bullfrog84Bullfrog84
Thank you very much! Most of the solutions have point to creating the checkbox the old way (https://salesforce.stackexchange.com/questions/101562/slds-and-inputfield-checkbox), but this was the issue for me as I was unable to assign to the checked attribute.