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