[SalesForce] Lightning inputText component readonly

I have ui:inputText component which is something like this:

<ui:inputText updateOn="keyup"
   keyup="{!c.keyPressController}"
   class="slds-input slds-combobox__input"
   aura:id="comboBox"
   value="{!v.searchKey}"
   placeholder="{!v.placeholder}"/>

Is it possible to make it readonly something like this?

<input type="text" class="slds-input slds-combobox__input" readonly="" value="hello" />

Best Answer

You can use enhanced version of ui:inputText which is lightning:input. It has readonly as attribute

<lightning:input name="quantity" value="1234567890"
 label="Quantity" maxlength="10" readonly="true" />

Same code can be written as

<lightning:input onchange="{!c.keyPressController}"
   class="slds-input slds-combobox__input"
   aura:id="comboBox"
   value="{!v.searchKey}"
   placeholder="{!v.placeholder}" readonly="true"/>
Related Topic