You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
Multiple radio button groups in LWC
LWC renders first and last radio button groups fine but but none in between. If I reference 1 or 2 picklist group I am ok but 3 or more none of the picklist in in the middle render any values.
import { LightningElement,wire, track } from 'lwc'; import { getPicklistValues } from 'lightning/uiObjectInfoApi'; import { getObjectInfo } from 'lightning/uiObjectInfoApi'; import LEASE_OBJECT from '@salesforce/schema/Lease_Payment_Term__c'; import Accounting_Type from '@salesforce/schema/Lease_Payment_Term__c.Accounting_Type__c'; import Type__c from '@salesforce/schema/Lease_Payment_Term__c.Type__c'; export default class GetPickListValueInLWC extends LightningElement { @track selectedValue; @track options = []; @track options1 = []; @track options2 = []; @wire(getObjectInfo, { objectApiName: LEASE_OBJECT }) objectInfo; @wire(getPicklistValues, { recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName : Accounting_Type }) ATPicklistValues ({error, data}) { if(data) { let optionsValues = []; for(let i = 0; i < data.values.length; i++) { optionsValues.push({ label: data.values[i].label, value: data.values[i].value }) } this.options = optionsValues; window.console.log('optionsValues ===> '+JSON.stringify(optionsValues)); } else if(error) { window.console.log('error ===> '+JSON.stringify(error)); } } @wire(getPicklistValues, { recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName : Type__c }) TPicklistValues ({error, data}) { if(data) { let optionsValues = []; for(let i = 0; i < data.values.length; i++) { optionsValues.push({ label: data.values[i].label, value: data.values[i].value }) } this.options1 = optionsValues; window.console.log('optionsValues ===> '+JSON.stringify(optionsValues)); } else if(error) { window.console.log('error ===> '+JSON.stringify(error)); } } @wire(getPicklistValues, { recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName : Payment_Frequency }) TPicklistValues ({error, data}) { if(data) { let optionsValues = []; for(let i = 0; i < data.values.length; i++) { optionsValues.push({ label: data.values[i].label, value: data.values[i].value }) } this.options2 = optionsValues; window.console.log('optionsValues ===> '+JSON.stringify(optionsValues)); } else if(error) { window.console.log('error ===> '+JSON.stringify(error)); } }
HTML
<template> <lightning-record-edit-form record-id={recordId} object-api-name="Lease_Payment_Term__c" onsuccess={handleSuccess} onsubmit ={handleSubmit}> <lightning-messages> </lightning-messages> <lightning-output-field field-name="Lease__c"> </lightning-output-field> <lightning-input-field field-name="Name"> </lightning-input-field> <lightning-radio-group name="ATradioGroup" if:true={wiredPicklistValues.data} label="Accounting Type" options={options} value={value} type="radio"> </lightning-radio-group> <lightning-radio-group name="TradioGroup" label="Type" options={options1} value={value} type="radio"> </lightning-radio-group> <lightning-radio-group name="PaymentradioGroup" label="Payment Frequency" options={options2} value={selectedValue} onchange={handleChange2} type="radio"> </lightning-radio-group>
All Answers
recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName : Payment_Frequency //I don't see payment_Frequence defined
I think you need to add import field line to the code to make the code work:: (assume field api name is Payment_Frequency__c)
import Payment_Frequency from '@salesforce/schema/Lease_Payment_Term__c.Payment_Frequency__c';
Suggestion:
1.line 8 should be changed to make it consistent with other fields. replace type__c by Type.
import Type from '@salesforce/schema/Lease_Payment_Term__c.Type__c';
2. Consequently line 43 should be changed to:
fieldApiName : Type
I do have import Payment_Frequency just forgot to add it to post. Updated based on your suggestion, Do you see any other reasons why this is behaving the way it is?
Thanks,
P
window.console.log('optionsValues ===> '+JSON.stringify(optionsValues));
import PaymentType from '@salesforce/schema/Lease_Payment_Term__c.Type__c'; //make sure type__c is a valid picklist data type and the picklist values are avaible on the default record type
2. Consequently line 43 should be changed to:
fieldApiName : PaymentType
thanks
P
thanks,
P