I want to get and set 'disabled' and 'value' attributes of this lightning component:

<lightning:select aura:id="myId" name="select" label="Valore" required="true" onchange="{!c.tipoChanged}" value="{!v.caseItem.RRT_IRM_Meter__c}">
<aura:iteration items="{!v.listaSelect}" var="option"> 
    <ui:inputSelectOption text="{!option}" label="{!option}"/>

How can I do that without using {!v.mapping_attributes} in my cmp page?

I'm trying this solution but does not work:

tipoChanged : function(component, event) {
var src = event.getSource();
var tipo = src.get("v.value");
}  }
  • You need to declare an <aura:attribute name="myAttr"....> tag in your component. Once you have that you will be able to use the component.get("v.myAttr"); and component.set("v.myAttr", "New Value"); methods. Have you gone through the Lightning Component Trailhead Modules? – John Thompson Sep 15 '17 at 3:16

You can simply do this using

component.find("myId").set("v.disabled", true); //or false
component.find("myId").set("v.value", anyValue);

Working with Attribute Values in JavaScript

  • And how to get the nested value? In the same way does not work: component.find("myId").get("v.value"); – Noomak Sep 14 '17 at 14:59
  • @Noomak as you want the select option value so this will also work component.get("v.caseItem.RRT_IRM_Meter__c"); – Tushar Sharma Sep 14 '17 at 16:11

You can set by finding Component using aura:id Click how to Find Component and Click How to Set Values to component attributes

Example as per your code


tipoChanged : function(component, event) {
    var src = event.getSource(),
        tipo = src.get("v.value");
    if(tipo == 'Orario ') {
       component.find("myId").set("v.disabled",true); // set value true or false
  • 3
    Please do not add just code, but rather use words to explain what needs to be done and why. Code dump answers often end up in the Low Quality review queue, as this one did. – Adrian Larson Sep 14 '17 at 14:08

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.