function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sandeep Krishna 34Sandeep Krishna 34 

Save seleceted checkbox group values in a text field in lightning record edit form in lwc

JS:
----
import { LightningElement,api } from 'lwc';
import TITLE_FIELD from '@salesforce/schema/Contact.Title';
export default class RecordEditFormLWC extends LightningElement {
// Expose a field to make it available in the template
    selectedValues = TITLE_FIELD; //t to store in a title text field
    // Flexipage provides recordId and objectApiName
    @api recordId;
    @api objectApiName;
    value = [];
    get options() {
        return [
            { label: 'Ross', value: 'option1' },
            { label: 'Rachel', value: 'option2' },
        ];
    }
    get selectedValue() {
        return this.value.join(',');
        console.log('selected values are '+value);
    }
    handleChange(e) {
        this.value = e.detail.value;
    }
}

HTML:
-------
<template>
<lightning-record-edit-form
    object-api-name="Contact"
    record-id={recordId}>
    
 <lightning-checkbox-group name="Checkbox Group"
                              label="Checkbox Group"
                              options={options}
                              value={value}
                              onchange={handleChange}></lightning-checkbox-group>
                                  <p>Selected Values are: {selectedValues}</p>
<lightning-input-field field-name={selectedValue}></lightning-input-field>
    <div class="slds-var-m-top_medium">
        <lightning-button variant="brand" type="submit" label="Save">
        </lightning-button>
    </div>
</lightning-record-edit-form>
</template>
Best Answer chosen by Sandeep Krishna 34
mukesh guptamukesh gupta
Hi Sandeep,

Please use below code:-
 
<lightning-input-field field-name={selectedValues} value = {selectedValue}></lightning-input-field>


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

All Answers

mukesh guptamukesh gupta
Hi Sandeep,

Please use below code:-
 
<lightning-input-field field-name={selectedValues} value = {selectedValue}></lightning-input-field>


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
This was selected as the best answer
Sandeep Krishna 34Sandeep Krishna 34
HI Mukesh,

it  is Saving slected options into text field in the backed 
and also creating text field in the UI. can we hide or stop creating that text field 

Thanks,
Sandeep 
 
mukesh guptamukesh gupta
HI Sandeep,

Yes you can hide:-
 
<lightning-input-field class="slds-hide" field-name={selectedValues} value = {selectedValue}></lightning-input-field>


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh