3

I am using lightning:recordEditForm to display records that may be new or existing. This is working nicely, however I now want to preset one of the fields. The fields are displayed using lightning:inputField components.

I understand that this is potentially stretching lightning:recordEditForm beyond its intended use, but since I get query & save functions OOTB I would very much like to continue using it.

So is there a way, using a secret facet or even JS to change field values after they are queried by the component? If not what's the next best thing that doesn't involve Apex?

0

2 Answers 2

3

Not sure if this is the best solution but basically I tried to set the field value after component-init and it worked:

doInit : function(component, event, helper) {
    var fieldValue = component.get('v.fieldValue');
    component.find('input_field').set('v.value', fieldValue);
}

where input_field is the id of the target lightning:inputField component:

<lightning:inputField fieldName="Field__c" aura:id="input_field"/>

In my scenario I wanted to have this field hidden so I set the style accordingly and the field got populated "in behind the scenes".

2
  • How did you hide the field?
    – iloveseven
    Aug 17, 2018 at 16:10
  • Did you use aura:if or did you add a css class to the component? Here is the documentation which makes me ask this.
    – iloveseven
    Aug 17, 2018 at 18:11
1

You can also use value attribute.

<lightning:inputField fieldName="Field__c" value={!v.foo}/>

1
  • 1
    That does not work. If you will try to submit such a lightning:recordEditForm it will give you an error due to lacking fields.
    – iloveseven
    Aug 17, 2018 at 20:47

You must log in to answer this question.

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