This is the third step in the Property Editor tutorial. This part shows how to integrate built-in Umbraco Contexts. For this sample, let us use the UmbNotificationContext for some pop-ups and the UmbModalManagerContext. UmbNotificationContext shows a notification when the Trim button is clicked and the input exceeds the maxChars limit.
With the notification context in place, update the #onTrimText method.
Check whether the input length is less than or equal to the maxChars value. If so, a notification is shown to indicate there is nothing to trim.
Use the NotificationContext's peek method here. It has two parameters UmbNotificationColor and an UmbNotificationDefaultData object.
Add the #onTextTrim()method above the render() method:
Add a click event to the trim text button in the render() method:
If the input length is less or equal to the maxLength configuration, a notification is displayed when clicking on the Trim button.
Trim Button Notification
Adding more logic to the context
Continue by adding more logic. If the length exceeds maxChars, show a confirmation dialog before trimming.
Here, use the ModalManagerContext which has an open method to show a dialog.
As with the notification context, import it and consume it in the constructor.
Add the following import in the suggestions-property-editor-ui.element.ts file:
Update the notification import to remove the UmbNotificationContext type, which is no longer needed:
Update the constructor to consume the UMB_MODAL_MANAGER_CONTEXTand the UMB_CONFIRM_MODAL.
Add more logic to the onTextTrim method:
See the entire file: suggestions-property-editor-ui.element.ts
Run the command npm run build in the suggestions folder.
Run the project.
Go to the Content section of the Backoffice.
Ask for suggestions and click on the Trim text button. If the suggested text is long enough to be trimmed, you will be asked for confirmation:
Confirmation message
Enforcing the Character Limit
The maxlength attribute on uui-input only provides visual feedback. It highlights the input red when the limit is exceeded, but does not prevent saving or publishing.
To enforce the limit properly, your property editor needs to be a form control.
Making the editor a Form Control
1
Import UmbLitElement and UmbFormControlMixin
2
Update the Lit import
Remove UmbElementMixin and LitElement from the @umbraco-cms/backoffice/external/lit import as they are no longer needed.