'PrimeFaces datePicker set current date on enter

I use the PrimeFaces datePicker. After the calender opens I want to apply the current date when enter is pressed and no date was selected.

enter image description here

This works in the jQuery datePicker (https://jqueryui.com/datepicker/) but not in PrimeFaces. If there is an option for this behaviour I fail to see it.

It ist working in PrimeFaces v8.0 but not in v11.0.0.

Thanks in advance for any help!

Workaround

For v11.0.0 I can still use the calendar component. There the behaviour is still the same as in v8.0. So I have a temporary workaround.`

Solution

I used JavaScript code from Melloware and turned it into a function. Since I have a lot of datePickers in the application without a widgetVar I used the given event to determine the component.

function applyDateOnEnter(event) {
    const datePicker = PrimeFaces.getWidgetById(event.target.parentNode.id);

    if (event.keyCode === 13 && datePicker.getDate() === null) {
        datePicker.setDate(new Date());
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source