Directory

← Back

Tuning DateField

A DateField alternative which can be customized with custom styles and tooltip

Author

Contributors

Rating

Tuning DateField is a highly customizable alternative to Vaadin native DateField.

  • You can customize styles and cell rendering.

  • There is also an inline mode that displays the calendar directly.

  • From 1.19.0-vaadin8 version, java.time is used instead of Joda Time LocalDate (http://www.joda.org/joda-time/). You can wrap new version into CustomField that uses Joda for backward compatibility

  • A 3 resolution calendar (day, month, year) is used for fast time travelling

Go to https://github.com/fdreyfs/vaadin-tuning-datefield for installation instructions.

Sample code

final TuningDateField tuningDateField = new TuningDateField("Tuning DateField with US holidays");

// Add a cellItemCustomizer for holidays
tuningDateField.setCellItemCustomizer(new CellItemCustomizerAdapter() {

    private HolidayManager holidayManager = HolidayManager.getInstance();

    @Override
    public boolean isEnabled(LocalDate date, TuningDateField calendar) {
        return !holidayManager.isHoliday(date);
    }

    @Override
    public String getTooltip(LocalDate date, TuningDateField calendar) {
        if (holidayManager.isHoliday(date)) {
            Holiday holiday = holidayManager.getHolidays(date.toInterval()).iterator().next();
            return holiday.getDescription();
        } else {
            return null;
        }
    }

    // CSS :
    // .tuning-datefield-calendar .holiday {
    // background-color: rgba(233, 237, 107, 0.5);
    // }
    @Override
    public String getStyle(LocalDate date, TuningDateField calendar) {
        if (holidayManager.isHoliday(date)) {
            return "holiday";
        } else {
            return null;
        }
    }
});

// A listener for date change which changes the date range
tuningDateField.addDateChangeListener(new DateChangeListener() {

    @Override
    public void dateChange(DateChangeEvent event) {
        // Access the LocalDate model instead of the value (which is a String)
        LocalDate localDate = tuningDateField.getLocalDate();
        // Modify the date range on the fly
        tuningDateField.setDateRange(localDate, null, "Allowed date start at " + localDate);
    }
});
InlineTuningDateField inlineTuningDateField = new InlineTuningDateField();
inlineTuningDateField.setControlsEnabled(false);

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

#20 Fixed NPE when calling removeDateRange() method. Thanks to ohens for spotting the bug

Released
2017-08-03
Maturity
BETA
License
Apache License 2.0

Compatibility

Framework
Vaadin 8.0+
Vaadin 7.7+ in 0.18.0
Vaadin 7.1+ in 0.17.0
Browser
Internet Explorer
Firefox
Opera
Safari
Google Chrome
Internet Explorer
Internet Explorer
Internet Explorer
Online