1

I have an input in a form built with aura (Salesforce JS framework):

<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 ?

2
  • The change event can be used here. See @ MDN Commented Apr 4, 2019 at 8:46
  • I don't know "aura" at all. But I can guess that the framework is listening to the input events so it's not enough to just change the value. There is a similar issue maybe it can give you a direction to the solution. Also, there is dedicated stackexchange site for salesforce maybe they could give you better answers. Commented Apr 4, 2019 at 9:09

1 Answer 1

0

You need to create an attribute of string type.

<aura:attribute name="myInputValue" type="String" />

Pass the attribute to the value property of the input tag.

<input .... value="{! v.myInputValue}" />

Now, whenever you want to change the value in the input, you can simply do this from your javascript function:

component.set('v.myInputValue, "My new String" />

Important Note: Salesforce frameworks don't allow DOM level manipulation due to a security architecture called Locker service. It is not advisable to follow DOM level Manipulation. Instead, follow the state-based approach like above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.