user1072089 user1072089 - 3 months ago 52
jQuery Question

PrimeFaces calendar has old value in onblur event

I'm trying to copy calendar's value into inputText field (don't ask me why) in the following way:

<p:calendar id="cal" widgetVar="calWidget"
onblur="PF('inputWidget').val(PF('calWidget').val());"/>
<p:inputText id="text" widgetVar="inputWidget" />


I've overridden PF functions, that's all working fine, the problem is that inputText gets previous selected date i.e. inputText is always one step behind with values. Is this expected behaviour and does anyone have any suggestions? Thanks.

P.S. I tried simpler solution also, same thing happens:

onblur="PF('inputWidget').val(this.value);"

Answer

Use dateSelect event:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head />
<h:body>
    <h:form>
        <p:calendar value="#{myDate}">
            <p:ajax event="dateSelect" update="dateOutput" />
        </p:calendar>
        <p:inputText id="dateOutput" value="#{myDate}" />
    </h:form>
</h:body>
</html>
Comments