2

I have a lightning-input-field inside a lightning-record-edit-form, used to create records. The field-name is a picklist field which uses a Picklist Value Set, with one default value.

When the form is loaded, the initial field value is undefined, but displays the default value. When the picklist is used to select another value, it is changed from undefined to whatever was selected, as evidenced by the onchange handler output.

I can use getObjectInfo to @wire the object info and resolve the default record type Id (or hardcode the default 012000000000000AAA), then use that value to getPicklistValues to @wire the default value for the picklist which seems to initialize the value.

That seems like a lot of work to get the field value to properly reflect the displayed value. Are there simpler ways to get this functionality?

0

I believe this is made as such by design. The variable (let's call it myValue) you are setting as the 'value' attribute of the lighting-record-edit-form is not initialized in Javascript I assume?

If you wish to use the form as a placeholder for one or more fields of a certain SObject (without ever submitting the form and e.g. using the onchange event as you are currently doing), I believe the only option to pre-populate the myValue variable would be as you describe in your original question (getObjectInfo + getPicklistValues).

However, when using a lightning-record-edit-form with a submit action, the currently filled in value (in this case the default value) will be set correctly in the data.fields properties of the event parameter of your onsubmit-handler.

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