2

I'm finding the component.set method only works on lightning:inputField components when the user has not changed the value in that field. See code example below.

Component:

<lightning:recordEditForm aura:id="editForm"  objectApiName="Account" recordId="0010G00002JEU4OQAX" > 
    <lightning:inputField fieldName="Rating" onchange="{!c.setDemoValue}" />
    <lightning:inputField aura:id="nom" fieldName="Name" />
</lightning:recordEditForm>

Controller:

({ setDemoValue : function(component, event, helper) { console.log('before value: ', component.find('nom').get('v.value')); component.find("nom").set("v.value", "temp"); console.log('after value: ', component.find('nom').get('v.value')); } })

If you change the "Rating" once, you can see the code work as expected. In the javascript console you can see it log out:

before value:
after value: temp

Now change the Name field from "temp" to "hello world", and change the rating again.

before value: hello world
after value: hello world

This seems like a defect to me (I would expect after value to be "temp"), but im not sure if there is a workaround or if I am doing something wrong. Thanks!

7
  • have you tried by setting a value attribute to the field?
    – glls
    Aug 22, 2018 at 16:54
  • yeah -- still see the issue
    – Phil Rymek
    Aug 22, 2018 at 16:55
  • 1
    i saw a different post where the recommendation was to use to change hanlder with inputfield. just an alternate suggestion to see if this can help you move on.salesforce.stackexchange.com/questions/142908/…
    – Rao
    Aug 22, 2018 at 16:56
  • @Phil Rymek, what is your specific use case? why would you want to overide what the user enters in a field while they change it in the layout, or after? (out of curiosity) if its the later, why not just set the field value onsubmit ?
    – glls
    Aug 22, 2018 at 17:26
  • 1
    Not yet but I will work towards it and use a solution like the one you described below. Thanks for your help. Spoke with SFDC and they believe this is working as intended, as a mechanism to prevent you from overwriting user data. Seems like there should be a function you can call to overwrite this, like a "clean()" or something.
    – Phil Rymek
    Aug 23, 2018 at 14:19

1 Answer 1

2

This is not the prettiest of workarounds, but, due to a similar problem I had faced in the past, I ended up hiding the inputFields display:none and using lightning:input fields when I rendered my component.

For example:

    <lightning:inputField fieldName="Subject" style="display:none;"/>
    <lightning:inputField fieldName="Description" style="display:none;"/>


    <lightning:input aura:id="test"  label="Subject" name="Case Subject" onblur="{!c.itemsChange}"/>

    <lightning:textarea label="Description" name="Case Description" maxlength="300" onblur="{!c.itemsChange}"/>

    <lightning:input type="checkbox" label="Clear" name="Clear" onchange="{!c.clear}"/>

and in my controller, i simply do what one would expect to work with a lightning:inputField

clear :  function(component, event, helper) {
    component.find("test").set("v.value", "");
},

Since the above 'leaves my inputFields hidden and unmodified, I actually have to populate the fieldnames on form submit:

handleRecordSubmit: function(component, event, helper) {
    event.getParams().fields.FIELDNAME = 'the lightning:input field value';
}

for what its worth, I know there are multiple known issues with the lighting:recordEdit form, and I wouldnt be surprised if this becomes one of them:

https://success.salesforce.com/issues_index?search=lightning%3AinputField

Looks like a similar known issue to :

https://success.salesforce.com/issues_view?id=a1p3A000000mDOkQAM

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .