Skip to content

Commit 4ca68d6

Browse files
authored
Add client-side validation for RTE (#18257)
1 parent 280cb7f commit 4ca68d6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.component.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
}
8484
}));
8585

86+
8687
vm.layout = []; // The layout object specific to this Block Editor, will be a direct reference from Property Model.
8788
vm.availableBlockTypes = []; // Available block entries of this property editor.
8889
vm.labels = {};
@@ -190,6 +191,9 @@
190191
vm.containerHeight = "auto";
191192
vm.containerOverflow = "inherit"
192193

194+
// Add client validation for the markup part.
195+
unsubscribe.push($scope.$watch(() => vm.model?.value?.markup, validate));
196+
193197
//queue file loading
194198
tinyMceAssets.forEach(function (tinyJsAsset) {
195199
assetPromises.push(assetsService.loadJs(tinyJsAsset, $scope));
@@ -337,6 +341,18 @@
337341
}
338342
}
339343

344+
function validate() {
345+
var isValid = !vm.model.validation.mandatory || (
346+
vm.model.value != null
347+
&& vm.model.value.markup != null
348+
&& vm.model.value.markup != ""
349+
);
350+
vm.propertyForm.$setValidity("required", isValid);
351+
if (vm.umbProperty) {
352+
vm.umbProperty.setPropertyError(vm.model.validation.mandatoryMessage || "Value cannot be empty");
353+
}
354+
};
355+
340356
// Called when we save the value, the server may return an updated data and our value is re-synced
341357
// we need to deal with that here so that our model values are all in sync so we basically re-initialize.
342358
function onServerValueChanged(newVal, oldVal) {

0 commit comments

Comments
 (0)