Details
-
Improvement
-
Resolution: Unresolved
-
Major
-
None
-
None
-
None
-
Unknown
-
Description
Java macros can declare constraints on their parameters with Bean Validation annotations, such as @Min, @Max or @Pattern. These constraints are only checked when the macro is rendered: the parameter descriptor sent to the WYSIWYG editor does not carry them, so the Edit Macro dialog accepts and saves any value.
For example, the start and depth parameters of the Table of Contents macro declare @Min(1), but their descriptor only has "displayType": "int" and a default value.
Steps to reproduce
- Edit a page with the WYSIWYG editor.
- Insert the Table of Contents macro.
- Type 0 in the depth parameter and submit.
Expected
The field does not accept a value below 1. An invalid value is flagged next to the field and the dialog does not submit until it is fixed.
Actual
The dialog submits, and the macro renders "Invalid macro parameters used for the [toc] macro. Cause: [Failed to validate bean: [must be greater than or equal to 1]]", which does not name the parameter.
Proposal
- Expose the constraints of a parameter in its descriptor, for example a minimum, a maximum and a pattern.
- Use them in the edit templates of the Edit Macro dialog, for example the min and max attributes of the number input proposed in XWIKI-25182, so that the browser validation the dialog runs before submitting covers them.
XWIKI-25197 proposes the same constraints for wiki macro parameters.
Found while auditing the Table of Contents macro: https://design.xwiki.org/xwiki/bin/view/Proposal/WYSIWYGusabilityofXWikimacros/Macros/toc/
Attachments
Issue Links
- relates to
-
XWIKI-25182 Numeric macro parameters accept any text in the Edit Macro dialog
-
- Open
-
-
XWIKI-25197 Allow wiki macro parameters to declare a range or a format for their value
-
- Open
-