You need to sign in to do that
Don't have an account?
Sandeep 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>
----
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>
Please use below code:-
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
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
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
Yes you can hide:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh