+ Start a Discussion
Ajith Selvaraj 2Ajith Selvaraj 2 

how to display n input fields in lightning component. where n is the value get from a user. Is it possible.?

how to display n input fields in lightning component. where n is the value get from a user. Is it possible.? suppose im getting 5 as input value and I want to display 5 input field in same page. here is the small snipet. but dot know to make more changes in it. please help with this.
<aura:component >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="keywords" type="List" default="[{value:''},{value:''},{value:''},{value:''}]" />
    <aura:iteration items="{!v.keywords}" var="item" indexVar="i">
    <lightning:input label="Keyword" value="{!item.value}" />
</aura:iteration>
</aura:component>

({
	doInit : function(component, event, helper) {
      alert('1');  
      var keywords = component.get("v.keywords").map(item => item.value);
        alert('1');
	}
})
ShirishaShirisha (Salesforce Developers) 
Hi Ajith,

Yes,it is possible with the lightning component using lightning:input component to get the inputs by the user.Please find the sample code with the example on how the user can give the values to the fields in the below link:

https://trailhead.salesforce.com/content/learn/modules/lex_dev_lc_basics/lex_dev_lc_basics_forms

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri