I want to get input field type information in my lightning javascript controller. How is that possible?

For ex:

   <lightning:input type="number" value="{!v.value1}"/>
   <lightning:input type="text" value="{!v.value2}"/>

Is there any work around or method using which i can get whether the field type is 'text' or 'number' in lightning javascript controller?



If you add an aura:id to your input field, you can access the input element in javaScript Controller:-

<lightning:input aura:id="inputCmp" type="number" value="{!v.value1}" />

In the controller, you can access the type of the input field as below:-

var inputCmp = component.find("inputCmp");
var type = inputCmp.get("v.type");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.