Lightning Web Components – Make LWC’s targetConfig Property Mandatory

configurationlightning-web-componentsxml

How can I make some properties in the meta file mandatory?

I have defined a few properties in below format

<targetConfigs>
  <targetConfig targets="lightning__RecordPage">
    <property name="somenumber" label="Some Number" type="Integer" default="0" />
  </targetConfig>
</targetConfigs>

Although I have given a default value, but it will be a problem if some admin will delete the default value. (I have to make this property configurable for admins).
So, how to make the property mandatory?

I'm trying to find something similar to "Required Attributes" feature mentioned here.

Note:- Most of my properties are either String (with free text and not with apex data source) or Integer

Best Answer

Unless I'm missing something with your question, why can't you just add the required attribute to your property?

e.g.

<targetConfigs>
  <targetConfig targets="lightning__RecordPage">
    <property name="somenumber" label="Some Number" type="Integer" default="0" required="true" />
  </targetConfig>
</targetConfigs>

For more info: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_configuration_tags

Related Topic