I am trying to access the value of a tag within a controller. I have tried component.find("selectId").getElement().value but the value field does not seem to be exposed for selects. The above works for determine the value of other forms. This is not being done within another component.

Test Component:

<aura:component >
<div class="slds-form-element">
    <label class="slds-form-element__label" for="select-01">Select Label</label>
    <div class="slds-form-element__control">
        <div class="slds-select_container">
             <select aura:id="select-01" name="select-01" class="slds-select" onchange="{!c.onSelectChange}">
                <option>Option One</option>
                <option>Option Two</option>
                <option>Option Three</option>

Testing Controller:

onSelectChange : function(component, event, helper) {
console.log("Input Selected");
var selected = component.find("select-01").getElement();

I'm not sure if this is because I'm looking for the wrong thing, or is Locker Services just totally locking down selects.


If you peek in the Locker source code here you can see the whitelisted attributes: https://github.com/forcedotcom/aura/blob/master/aura-impl/src/main/resources/aura/locker/SecureElement.js

So you are right, value has not been whitelisted for <select> elements. (Hey SalesForce, maybe you should get on that!) However selected and value have been whitelisted for <option> elements. So you might instead be able to do something like this:

var selected = component.find("select-01").getElement()
    .children.find(function(option){return option.selected});

And now you'll end up with the option DOM node. Pardon if there are any flaws in my JS.

  • Thanks for the link to the white-list. I've seen a few comments from people about missing white-listed attributes so I wanted to see if it was intentional. – John Jul 2 '16 at 13:51

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.