| Validating a custom field [message #1060593] |
Mon, 27 May 2013 04:27  |
Urs Beeli Messages: 167 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
I've created a rather complex custom field that lets me select dates using various methods. I now have the requirement that depending on the situation I need to define a minimum and maximum number of days that must be selected.
I was hoping to add some way of checking the currently selected number of days in a method like execValidateValue() after each change of selection and when clicking the ok button.
Is there an easy way to add this functionality without having to implement all of IValueField (which would be massive overkill in my case)? Ideally I would like the functionality to be caught by the form without having to add extra code to the form.
|
|
|
|
| Re: Validating a custom field [message #1060624 is a reply to message #1060597] |
Mon, 27 May 2013 07:22  |
Urs Beeli Messages: 167 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
The class definition of my custom field looks as follows:
public abstract class AbstractTagesfilterField extends AbstractCustomField implements ITagesfilterField {
where ITagesfilterField defines a few setters/getters to access the selected days.
However, I think the solution to my problem is easier than I had anticipated. The only "loss" of my solution is that the validation is not executed automatically, but needs to be triggered explicitely in my field.
I've added a method validateValue() which evaluates the min/max limites (defined as configuration properties) and the currently selected number of days. Depending on the outcome it just calls clearErrorStatus()/setErrorStatus() on the field. This is enough to be taken into account when I press the OK button on the form, the only thing that remains is to also use this information to graphically indicate the error status on the control itself. To handle dynamic changes, I am calling validateValue() in my UIFacade whenever a user interaction (mouse click) effects a change in selected days.
Below you see the result of all this (left side: invalid selection, right side: valid selection):

Attachment: kalender.png
(Size: 150.17KB, Downloaded 42 times)
[Updated on: Mon, 27 May 2013 07:23] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02254 seconds