Skip to content

Instantly share code, notes, and snippets.

@andrii-solokh
Created July 31, 2020 11:36
Show Gist options
  • Save andrii-solokh/9fb2a85650f3bf1e97f30a27d01ea6cc to your computer and use it in GitHub Desktop.
Save andrii-solokh/9fb2a85650f3bf1e97f30a27d01ea6cc to your computer and use it in GitHub Desktop.
LWC RecordTypeSelector
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