You need to sign in to do that
Don't have an account?
Custom Labels as values in LWC Radio Group
Hi Folks,
I am trying to assign Custom Labels as a Radio Group values into LWC but with no success. Please share your thoughs how do I do that Properly?
- So I imported Custom labels into JS file.
- Stored them into label object
- How do assign it to "Options" that Radio group could use it?
Please see code below and screen shoot, how it should look like at the end.
HTML **************************************************************
<lightning-radio-group name="Random Radio"
label="Radio"
options={options}
value={value}
required
type="radio"
onchange= {handleChange}>
</lightning-radio-group>
JS ******************************************************************
import { LightningElement, wire, track, api } from 'lwc';
import customLabel1 from '@salesforce/label/c.label1';
import customLabel2 from '@salesforce/label/c.label2';
import customLabel3 from '@salesforce/label/c.label3';
export default class RandomClass extends LightningElement {
label {
label1,
label2,
label3
}
get options() {
return [
{ //Custom Label 1 Here },
{ //Custom Label 2 Here },
{ //Custom Label 3 Here },
];
}
}
we can import custom labels and while passing in JS , instead of hardcoding we can pass custom labels.
Here is the code.
HTML :
JS :
The UI :
Hope this helps , Kindly mark this as best answer .
Thanks,
karthik