问题
We're using the "Error Messages" XPages (native) control to show the validation errors to user. It works. The validation is done by setting the field as required and entering the field error message. Nothing special.
Now the requirement is to set the error messages in to the same order as they appear in the form. Is this possible?
I guess I could create a custom validator (Java) and doing all the form validations there in certain order (just tested the Validation interface... but not really used id, yet).
回答1:
There's the old (unresolved) argument: should the errors appear next to the control that failed the validation, on top of the form or next to the button you pressed for submission. I tend to put them next to the failed control and have ONE message next to the button reading: "Sorry I couldn't process the input, help me and fix the fields that have error messages next to them". Then sequence isn't an issue any more. If you want to be 100% sure you could instead of the summary control use the individual controls next to each other.
What anyway would be a nice exercise: let the error message control alter the css of the failed control, so it becomes clearer what to look out for.
回答2:
The Validations are fired one by one in order they are in the component tree. Depending on how you are wanting them to display you could move the components around and then style them with css. Or if you are really just wanting to move the order of the summary statements around in the Messages Box, I would just use some JS to move them around I believe they just render as a UL. Only having one Validator won't really work as the same validator will get fired for every component in the order of the component tree.
来源:https://stackoverflow.com/questions/9126614/how-to-set-the-order-of-validation-messages