0

I have an input in a form built with aura:

<input class=" input uiInput uiInputText uiInput--default uiInput--input" type="text" aria-describedby="5284:0" placeholder="" id="7:4790;a" data-aura-rendered-by="17:4790;a" data-aura-class="uiInput uiInputText uiInput--default uiInput--input" data-interactive-lib-uid="54" aria-required="true">

I need to change the value of this input using javascript. However, when doing:

document.getElementById("7:4790;a").value = "random value";

Visually, it changes the value in the input, but it is not taken into account when saving as if I didn't change anything.

How can I achieve this ? Do I need to trigger a specific event so that aura takes notice of the new data ?

1

If you convert your <input> element to a <lightning:input> or <ui:input> component, then add aura:id="myInputField" to the component then you can use the following javascript to adjust the value:

component.find("myInputField").set("v.value", "random value");

As best practice, you should always use <lightning:input> or <ui:input> components - they're much easier to work within the aura framework

|improve this answer|||||

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.