The mindate/maxdate not working with timeOnly mode on DatePicker and Calendar
See original GitHub issue1) Environment
- PrimeFaces version: 7.0
- Does it work on the newest released PrimeFaces version? No (7.0)
- Does it work on the newest sources in GitHub? No
- Application server + version: Apache Tomcat 9
- Affected browsers: Any
2) Expected behavior
If I set an instance of java.util.Date for the maxdate attribute with time e.g. 19:00, datePicker should limit time selection to 19:00.
3) Actual behavior
A javascript exception is thrown and the datePicker initialization fails, making it unusable. (No popup on focus). The same is true for the mindate attribute. When removing the maxdate attribute, it works as expected but with unlimited time selection.
jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 Uncaught Unexpected literal at position 0 (anonymous) @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 setTimeout (async) k.readyException @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 (anonymous) @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 e @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 t @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 setTimeout (async) (anonymous) @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 c @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 fireWith @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 fire @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 c @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 fireWith @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 t @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 setTimeout (async) (anonymous) @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 c @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 fireWith @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 fire @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 c @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 fireWith @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 ready @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2 B @ jquery.js.xhtml?ln=primefaces&v=7.1-SNAPSHOT:2
4) Steps to reproduce
Just invoke following xhtml and watch the browser dev tools console:
5) Sample XHTML
<h:form>
<p:datePicker value="#{myBean.dateValue}" timeOnly="true"
pattern="HH:mm" maxdate="#{myBean.dateMaxValue}" />
<p:commandButton value="submit" process="@form" update="out" />
<h:outputText id="out" value="#{myBean.dateValue}" />
</h:form>
6) Sample bean
package my.pkg;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
@Named
@ViewScoped
public class MyBean implements Serializable {
private static final long serialVersionUID = 1L;
private Date dateValue;
private Date dateMaxValue;
@PostConstruct
public void init() {
Calendar calendar = GregorianCalendar.getInstance();
// make it 01.01.1970 11:33:09
calendar.setTimeInMillis(0);
calendar.set(Calendar.HOUR_OF_DAY, 11);
calendar.set(Calendar.MINUTE, 33);
calendar.set(Calendar.SECOND, 9);
dateMaxValue = calendar.getTime();
}
public Date getDateValue() {
return dateValue;
}
public void setDateValue(Date dateValue) {
this.dateValue = dateValue;
}
public Date getDateMaxValue() {
return dateMaxValue;
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Ok my previous post is invalid - I picked up the wrong JQuery script with no FX. It’s not even required to get the uncompressed JQuery but just make Firefox dev tools stop on handled JS exceptions.
The error is thrown from line 733 in datepicker.js:
While:
see PR https://github.com/primefaces/primefaces/pull/5313