I have a lightning component which acts as a text area field. The mark up is as given below.

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes">
    <aura:attribute name="Label" type="String" />
    <aura:attribute name="fID" type="String" />

    <div class="slds-form-element">
        <label class="slds-form-element__label" for="{!v.itemID}">{!v.Label}</label>
        <textarea id="{!v.fID}" class="slds-textarea" rows="3" />

I am using this component in a parent form component. On click of a button from there I am fetching the values from inside all such child components which act as different field types using document.getElementById().value. It works for all <input> type tags but returns the value as undefined for the <textarea> tag.

Any suggestions regarding tackling such a scenario?

  • What does the rendered HTML look like? Does the textarea element have an id attribute on it when it is rendered? Is the result of document.getElementById(yourIdHere) null? Can you show the script demonstrating where you are passing the id to the getElement method?
    – Mark Pond
    Jul 12 '16 at 17:03
  • Hi Mark. The rendered HTML is the same as my markup. <div> <label> <textarea id="someID"> </div> What I found is that the issue was locker service. It started working as soon as i deactivated it. Jul 14 '16 at 5:28

The value property of textarea has just been whitelisted and should be available next week.


This is a Locker Service issue. Look at the source here: https://github.com/forcedotcom/aura/blob/master/aura-impl/src/main/resources/aura/locker/SecureElement.js

The value property of textarea has not been whitelisted. You could always use ui:inputTextArea instead.

This is the same issue as listed here: Unable to get textarea value with LockerService

Unfortunately they have not acted on that one yet.

  • Hi Charles. Thanks for the explanation. The only issue is that I need to access the element using 'document.getElementById()` and hence I need the id attribute to be present. And ui:inputTextArea has aura:id but not simple javascript id. Jul 13 '16 at 6:57
  • Also under Locker Service if you create your textarea using ui:inputTextArea you will not be able to find it by document.getElementById() due to it being in a different namespace. So yeah, if you absolutely must access it through the DOM you have no options right now. But why do you need to access it through the DOM?
    – Charles T
    Jul 13 '16 at 14:17
  • I deactivated locker service in my org and yes I am being able to access it through the DOM. I will have to explain the entire architecture to make the requirement lucid. In short, the elements that are being loaded on my page are skeleton components for various datatypes. They could be repeated based on the fields present in the fieldset that is being rendered. Hence to make each of them unique I need to set the IDs dynamically during page load. Jul 14 '16 at 5:17

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.