0

How can I get name of input text in lightning ? I was able to recover just the value and otherwise I have undefined as result

   <aura:handler name="change" value="{!v.filtreNameText}" action="{!c.filterChange}"/>
<lightning:input class="CASE" name="input2" value="{!v.filtreNameText}" />

ControllerJs

filterChange: function(component, event,helper) {
    var Nametxt = event.getParam("value");
    var Nametxxt = event.getSource().get("v.name");
    var Nametxxxt = event.currentTarget ;

    console.log(Nametxt+ " " + Nametxxt + " " + Nametxxxt);

}

1 Answer 1

0

As aura value change handler simply provides old and new value, easy solution is to use onchange action of lightning:input.

Component code:

<!-- Not needed:
<aura:handler name="change" value="{!v.filtreNameText}" action="{!c.filterChange}"/>
-->
<lightning:input class="CASE" name="input2" value="{!v.filtreNameText}" 
    onchange="{!c.filterChange}"/>

Client side controller function:

filterChange: function(component, event, helper) {
    console.log("value: " + event.getSource().get("v.name"));
    console.log("name: " + event.getSource().get("v.value"));
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .