I am trying to have two Javascript functions that are being called as soon as a user selects a date from a p:calendar.
Unfortunately, the onchange event is only being processed if the user types a date manually in the text field and tabs forward. The onselect event is not being fired at all.
The xhtml is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputScript library="js" name="custom.js" target="body" />
</h:head>
<h:body>
<p:log />
<h:form id="someForm">
<p:panelGrid columns="2">
<p:outputLabel for="myCalendar" value="Date: " />
<p:calendar id="myCalendar" onchange="alertDateSelected()" onselect="alertSelectEvent()" showOn="button" />
</p:panelGrid>
</h:form>
</h:body>
</html>
The Javascript code for the onselect and onchange events:
function alertDateSelected() {
PrimeFaces.info('Selected date from p:calendar');
}
function alertSelectEvent() {
PrimeFaces.info('Clicked p:calendar date selection button');
}
Is there a possibility to hook to the onchange/onselect event on p:calendar; e.g. if the user selects a date from the calendar panel or via the "Today" button? If so, what am I doing incorrectly?