This is step two in our guide to building a Property Editor. This step continues work on the Suggestion Data Type we built in part one but goes further to show how to add configuration options to our editor.
The steps we will go through in the second part are:
An important part of building good Property Editors is to build something flexible, so we can reuse it many times, for different things. Like the Rich Text Editor in Umbraco, which allows us to choose which buttons and stylesheets we want to use on each instance of the editor.
An editor can be used again and again, with different configurations, and that is what we will be working on now.
Adding settings object to umbraco-package.json
To add a Data Type configuration field when using our Suggestion Property Editor, open the umbraco-package.json file. Inside the meta object, we can add the settings object, which has the optional objects properties and defaultData.
Add some properties:
umbraco-package.json
..."meta": { ..."settings": {"properties": [ {"alias":"disabled","label":"Disabled","description":"Disables the suggestion button","propertyEditorUiAlias":"Umb.PropertyEditorUi.Toggle" }, {"alias":"placeholder","label":"Placeholder text","description":"A nice placeholder description to help out our editor!","propertyEditorUiAlias":"Umb.PropertyEditorUi.TextBox" }, {"alias":"maxChars","label":"Max characters allowed","description":"The maximum number of allowed characters in a suggestion","propertyEditorUiAlias":"Umb.PropertyEditorUi.Integer" } ] } ... }
In the section above, we added three configuration fields. Each entry in the properties collection represents a Configuration field. It contains the necessary information for that field.
The field labeled "Disabled" uses the Toggle Property Editor UI. This enables to switch the suggestion button on or off and provides the user with a toggle button.
The field labeled "Placeholder text" uses the TextBox Property Editor UI, allowing the user to write a text.
The field labeled "Max characters allowed" uses the Integer Property Editor UI, enabling the user to enter a numeric value.
The Property Editor UI needs to be declared as it declares what User Interface should be used for this field.
You can use any Property Editor UI to define Configuration fields. The alias of a given Property Editor UI can be found in Data Type configurations using that Property Editor.
We can now also set some default data on our new configurations: