Disabling selection of dates in a date field - gwt

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).

Related

Fullcalendar v5 - Drag and Drop an external event return current date and note the date where the element is dropped

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

How to set Minimum and maximum date in Datepicker Calander in JavaFx8?

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

How can I make a cell update with the current date, using a dropdown next to the cell?

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);
}
}

How can I tell a DefaultDataTable to refresh itself?

I am new to Wicket. I have a search page with two fields, startDate and endDate, inside a form that is inside a panel. The panel contains a DefaultDataTable. When the user submits the form, I use the startDate and endDate in the onSubmit() to get the results. However, my table remains empty. How do I tell the DefaultDataTable to refresh?
I have added a form and a submit button to this example. If I want to change the contents of the list, where do I do it?
Button submitButton = new Button("submitButton"){
#Override
public void onSubmit(){
System.out.println("submit button was clicked");
}
};
Form myForm = new Form("myForm");
myForm.add(submitButton);
add(myForm);
Ok, here is my comment as proper answer: make the DataProvider.iterator() dependend on the 2 Dates.

JQuery UI Datepicker Current Day

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.