I suspect I know the answer to this, but I’ll ask anyway : is it possible to set a minimum or maximum date for the DateField, so that the Pop-Up Calendar won’t allow to navigate-to-or-select before/after the given dates?
I realise I could (and would still need to) validate the date entered by the user, but it would be good to prevent the user selecting invalid dates using the calendar.
Context: Trying to allow the user to modify a from/to date range for searching.
I suspect this functionality isn’t supported, and I’m not sure whether it’s a common enough use-case to warrant a feature request. What do others think?
Hi, setting minimum and maximum dates is not currently supported at component level.
Of course you can implement own limitations at validation time. When thinking about the user experience, it would be best that DateField component would not allow selecting past given limits so that it’d work as client side validation. One issue I see there is that DateField selects the current date as default. If current date is not within the range of minimum and maximum dates, it would be problematic.
I remember having the same need in some past project for setting similar client side limitations, indeed this would be a good feature to have and not that complex to implement anyway. I think creating ticket to Vaadin trac for this feature request is a good idea.
It is a very common ‘use case’ to ONLY be allowed to select a date in the future.
Something as trivial as setting your next appointment or meeting. The past is not a valid date option for those of us without a Time Machine.
When I did this in Java Swing you could give a date range or a collection of dates that were valid. That went into a data model used to enable/able the widget.
Calendards are one of the most difficult controls when it comes to Internationalization. Unless you’ve been lucky enough to be born in London (GMT-0) and never have to support other locales it is always an insteresting problem domain. I haven’t even brought up all of the different calendars currently used as well as languages that read right to left.
/**
* Sets the start range for this component. If the value is set before this
* date (taking the resolution into account), the component will not
* validate. If <code>startDate</code> is set to <code>null</code>, any
* value before <code>endDate</code> will be accepted by the range
*
* @param startDate
* - the allowed range's start date
*/
public void setRangeStart(Date startDate) {
It is worth noting. If you use this setting and then bind it to a FieldGroup you get an error about the ‘loaded’ value being out of range when the FieldGroup bean is set to the component.
I tried it BEFORE loading the DB value and AFTER loading the DB value. I still see this error: Date is out of allowed range
As it is currently coded I don’t know how I could use it in a FieldGroup.
Cheers
_binder = new FieldGroup();
_binder.setItemDataSource(editObject);
_binder.bindMemberFields(this);
// cache the date value for logic
_cachedDate = _assessDate.getValue();
// lock the component selection down to FUTURE dates
_assessDate.setRangeStart(new Date()); // only future dates allowed