question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The mindate/maxdate not working with timeOnly mode on DatePicker and Calendar

See original GitHub issue

1) 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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Selaroncommented, Sep 3, 2019

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:

checkLiteral = function() {
	if (value.charAt(iValue) !== format.charAt(iFormat)) {
		throw "Unexpected literal at position " + iValue;
	}
	iValue++;
};

While:

vaue =  "11:33"
format = "HH:mm"
iValue = iFormat = 0
Read more comments on GitHub >

github_iconTop Results From Across the Web

maxDate and minDate not working properly · Issue #89 - GitHub
On Android platform after setting maxDate/minDate, disabled dates are rendered in the lighter color but it is still possible to set them.
Read more >
jquery datepicker range (mindate maxdate) is not working
When implementing the daterangepicker, I would receive a NaN value in the calendar every time I set both minDate & maxDate to a...
Read more >
Change how a date or time is displayed in a date picker, text ...
In the Display the time like this list, click (Do not display time). Click OK twice.
Read more >
Angular PrimeNG Calendar Component - GeeksforGeeks
Calendar component: It is used to display a month-wise calendar that allows the user to select dates and move to the next or...
Read more >
Calendar - PrimeVUE - PrimeFaces
Month picker is used to select month and year only without the date, set view mode as "month" to activate month picker. <Calendar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found