Please help.
How Can we set min and max date in date picker calendar in javafx8?
Or why not
minDate = LocalDate.of(1989, 4, 16);
maxDate = LocalDate.now();
datePicker.setDayCellFactory(d ->
new DateCell() {
#Override public void updateItem(LocalDate item, boolean empty) {
super.updateItem(item, empty);
setDisable(item.isAfter(maxDate) || item.isBefore(minDate));
}});
No need to create an extra datepicker just to store the max date.
It is possible to limit the dates available for being selected by user by disabling those days on a dayCellFactory and setting those dates range to you DatePicker, official docs can be found here, here is an example:
DatePicker myDatePicker = new DatePicker(); // This DatePicker is shown to user
DatePicker maxDate = new DatePicker(); // DatePicker, used to define max date available, you can also create another for minimum date
maxDate.setValue(LocalDate.of(2015, Month.JANUARY, 1)); // Max date available will be 2015-01-01
final Callback<DatePicker, DateCell> dayCellFactory;
dayCellFactory = (final DatePicker datePicker) -> new DateCell() {
#Override
public void updateItem(LocalDate item, boolean empty) {
super.updateItem(item, empty);
if (item.isAfter(maxDate.getValue())) { //Disable all dates after required date
setDisable(true);
setStyle("-fx-background-color: #ffc0cb;"); //To set background on different color
}
}
};
//Finally, we just need to update our DatePicker cell factory as follow:
myDatePicker.setDayCellFactory(dayCellFactory);
Now myDatePicker will not allow user to select dates after 2015-01-01 (Remeber, dates will be shown but no availble to be selected), here you can also create another temporary datePicker for Min date for setting available dates ranges, by the way these code have to be placed on initialize method of java controller
Related
i used fullcalendar v5 with external events that i can dropped on the calendar.
I have an issue and i don't understand what i'm doing wrong...
When i drag and drop an event, the drop function(info, date) return the curent date and not the date where the event was dropped.
/* initialize the external events
-----------------------------------------------------------------*/
var containerEl = document.getElementById('external-events-list');
new FullCalendar.Draggable(containerEl, {
itemSelector: '.fc-event',
eventData: function(eventEl) {
return {
title: eventEl.innerText.trim()
}
}
});
drop: function(info,date) {
console.log(moment(date).format('YYYY-MM-DD HH:mm:ss'));
$('#ModalAdd #start').val(moment(date).format('YYYY-MM-DD HH:mm:ss'));
$('#ModalAdd #end').val(moment(date).format('YYYY-MM-DD HH:mm:ss'));
$('#ModalAdd #task').val(info.draggedEl.innerText);
$('#ModalAdd').modal('show');
},
As you can see on the picture, the date in console.log or the date in the fields "start" and "end" on the form of the modal window are the current date...
I dont't understand....
Thank you !
screenshot
I am automating the application through protractor and as part of one testcase need to select the date, the date-picker definition is as below. I tried to select the date using sendkeys which is not working.
element(by.lid("new-transaction-doat-field)).sendKeys("24 Aug 2019");
Please help me in to select the date.
Note: lid is the custom attribute and to select the value by lid, create a custom attribute method in protractor
Two issues in your given code:
1) Should interact with a Input html element
2) sendKeys() can't interact with a readonly Input html element.
// because protractor not support invoke setAttribute api directly,
// need to using executeScript to inject DOM Javascript snippet into browser
// then execute the snippet in browser
browser.executeScript(
"arguments[0].setAttribute('value', arguments[1])",
element(by.css( '[lid="new-transaction-doat-field"] > span > input')).getWebElement(),
"24 Aug 2019"
)
Keep in mind, setAttribute() is not simulating user interact with web page from UI.
Please confirm it's acceptable from your test perspective.
I found the solution to select the date through datepicker where 'sendKeys' won't work as input is disabled. The solution is like how manually we will traverse through the calendar and select the date.
The code is as below:
this.selectDate = function (dateElement, dateValue, yearButton, arrowButton) {
var splitDate = dateValue.split('/');
var year = splitDate[2];
var month = splitDate[1];
var day = splitDate[0];
var monthName = getMonthName(month);
dateElement.click()
.then(() => yearButton.click())
.then(() => yearButton.click())
.then(() => selectYear(year, arrowButton))
.then(() => element(by.xpath("//span[text()='" + year + "']")).click())
.then(() => element(by.xpath("//span[text()='" + monthName + "']")).click())
.then(() => element(by.xpath("//span[text()='" + day + "']")).click());
};
async function selectYear(year, arrowButton) {
for(var i=0; i < 10; i++) {
var present = await element(by.xpath("//span[text()='" + year + "']")).isPresent()
if(present) {
break;
} else {
await arrowButton.click();
}
}
}
function takes inputs as dateElement, dateValue, yearButton - which is center button to traverse to years, arrowButton - previous or next button in the calendar
First script clicks on the year button in the center in the above image it is 'September 2019' , after that '2019' year calendar comes, it clicks on that again.
Then 2001 to 2019 calendar comes as below
if the year displays it clicks on that otherwise it clicks on 'previous' or 'next' button based on the date to select until it got displayed (looping for 10 times to search for the year, if not in 10 clicks throws error).
After year clicked, it clicks on month and day.
have you tried the .sendKeys() on the input?
element(by.model('dateModel')).sendKeys('dd mmm yyyy');
I'm using a date field in which I want to limit the date selection to a maximum of 90 days from the current date. How can i achieve this?
I tried dateField.setMaxvalue(maxDate), but I'm not able to limit the selection
I don't think the GWT datepicker has support for this.
You could use a library like GWT-Bootstrap3 which does have all this (https://gwtbootstrap3.github.io/gwtbootstrap3-demo/#dateTimePicker).
Or you could listen for events and rollback changes made by the user if selection was outside the valid range, and display a message to the user.
I second to the suggestion given by #Knarf. You could use GWT DatePicker class and listen for a ValueChangeEvent and in ValueChangeHandler, you could put your logic to check if the selected date is within your range - if not, you could show a message on your UI for the User to reselect a date within the date range (as per your requirement).
DatePicker datePicker = new DatePicker();
final Label text = new Label();
// Listen for a ValueChangeEvent and implement a ValueChangeHandler on your datePicker element
datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
public void onValueChange(ValueChangeEvent<Date> valueChangeEvent) {
Date inputDate = valueChangeEvent.getValue();
// Put your logic to test whether the selected date is within your range
String dateString = DateTimeFormat.getMediumDateFormat().format(inputDate);
text.setText(dateString);
}
});
Hope that this helps!
You can add a ShowRangeHandler to your datePicker. This is an example to restrict the datePicker to dates in the past only, you can adapt it to limit to 90 days:
datePicker.addShowRangeHandler(new ShowRangeHandler<Date>() {
#Override
public void onShowRange(ShowRangeEvent<Date> event) {
Date today = new Date();
Date date = new Date(event.getStart().getTime());
while (date.before(event.getEnd())) {
if (date.after(today) && datePicker.isDateVisible(date)) {
datePicker.setTransientEnabledOnDates(false, date);
}
CalendarUtil.addDaysToDate(date, 1);
}
}
});
The above mentioned solutions worked exactly the way i expected..Thank you.I used the bootstrap datepicker in the link (https://gwtbootstrap3.github.io/gwtbootstrap3-demo/#dateTimePicker).
I need to make Data Validation on a range of cells. I want a dropdown list, where the only option is the current date. To get the current date, I can use =TODAY(). The problem is, that the dates don't remain static. When the sheet recalculates, so will all the dates. I need the dates to remain the same.
How can I work around this?
I found a blog where the answer might be, but I can't see how the author has made his spreadsheet.
I will have a dropdown item which says "dags dato". Next i use an eventlistener that checks if the text in a cell is changed to "dags dato".
if so, it puts the current date in the cell, like this:
function onEdit(event)
{
var ss = event.source.getActiveSheet();
var r = event.source.getActiveRange();
var currentValue = r.getValue();
if(currentValue == "dags dato")
{
var dd = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd");
r.setValue(dd);
}
}
My page uses a JQuery UI Datepicker and loads with the current day selected and weekends and selected dates restricted.
I would like the current selected day to become unavailable at 2pm and the day move forward.
Can anyone help.
I would just use a variable for the the minDate
var dt = new Date();
if (dt.getHours() > 14) {
dt = dt.setDate(dt + 1); // go one day in the future
}
$(selector).datepicker({minDate: dt});
You'd just need to use the real javascript Date class methods - which I haven't used in a little while.