Created
July 31, 2020 11:36
LWC RecordTypeSelector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { wire, api } from 'lwc'; | |
import { getObjectInfo } from 'lightning/uiObjectInfoApi'; | |
import LightningRadioGroup from 'lightning/radioGroup' | |
export default class RecordTypeSelector extends LightningRadioGroup { | |
@api objectApiName | |
@wire(getObjectInfo, { objectApiName: '$objectApiName' }) wireOptions ({error, data}) { | |
if(data) { | |
let optionsValues = []; | |
let rtValues = Object.values(data.recordTypeInfos); | |
Array.from(rtValues).forEach((value, i) => { | |
if(value.name !== 'Master') { | |
optionsValues.push({ | |
label: rtValues[i].name, | |
value: rtValues[i].recordTypeId | |
}) | |
} | |
}) | |
this.options = optionsValues | |
} | |
else if(error) { | |
window.console.log(JSON.stringify(error)); | |
} | |
} | |
renderedCallback() { | |
this.addEventListener('change', this.handleChange) | |
} | |
handleChange(event) { | |
this.value = event.target.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment