Skip to content

Instantly share code, notes, and snippets.

@andrii-solokh
Created July 31, 2020 11:36

Revisions

  1. andrii-solokh created this gist Jul 31, 2020.
    34 changes: 34 additions & 0 deletions recordTypeSelector.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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
    }
    }