Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #360 from RishiRajAnand/datepickerfix
Browse files Browse the repository at this point in the history
Added Clear Button in DatePicker and DateTimePicker
  • Loading branch information
sjardine authored Apr 30, 2019
2 parents 8153624 + 960c742 commit 8e42aaf
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasMinView;
import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasPosition;
import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasShowTodayButton;
import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasShowClearButton;
import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasStartDate;
import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasStartView;
import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasViewSelect;
Expand Down Expand Up @@ -99,7 +100,7 @@
*/
public class DatePickerBase extends Widget implements HasEnabled, HasId, HasResponsiveness, HasVisibility, HasPlaceholder,
HasAutoClose, HasDaysOfWeekDisabled, HasEndDate, HasForceParse, HasFormat, HasHighlightToday, HasKeyboardNavigation,
HasMinView, HasShowTodayButton, HasStartDate, HasStartView, HasViewSelect, HasWeekStart, HasDateTimePickerHandlers,
HasMinView, HasShowTodayButton, HasShowClearButton, HasStartDate, HasStartView, HasViewSelect, HasWeekStart, HasDateTimePickerHandlers,
HasLanguage, HasName, HasValue<Date>, HasPosition, LeafValueEditor<Date>, HasEditorErrors<Date>, HasErrorHandler,
HasValidators<Date>, HasBlankValidator<Date> {

Expand Down Expand Up @@ -154,6 +155,7 @@ public void onBlur(BlurEvent event) {
private DatePickerMinView minView = DatePickerMinView.DAY;

private boolean showTodayButton = false;
private boolean showClearButton = false;
private boolean highlightToday = false;
private boolean keyboardNavigation = true;
private boolean forceParse = true;
Expand Down Expand Up @@ -446,6 +448,12 @@ public void setShowTodayButton(final boolean showTodayButton) {
this.showTodayButton = showTodayButton;
}

/** {@inheritDoc} */
@Override
public void setShowClearButton(boolean showClearbutton) {
this.showClearButton = showClearbutton;
}

/** {@inheritDoc} */
@Override
public void setStartDate(final Date startDate) {
Expand Down Expand Up @@ -649,7 +657,7 @@ protected void configure(final Widget w, final Widget container) {
this.remove(w.getElement());

configure(w.getElement(), container.getElement(), format, weekStart.getValue(), toDaysOfWeekDisabledString(daysOfWeekDisabled), autoClose,
startView.getValue(), minView.getValue(), showTodayButton, highlightToday, keyboardNavigation, forceParse, viewSelect.getValue(),
startView.getValue(), minView.getValue(), showTodayButton, showClearButton, highlightToday, keyboardNavigation, forceParse, viewSelect.getValue(),
language.getCode(), position.getPosition());
}

Expand Down Expand Up @@ -696,7 +704,7 @@ private native void setDaysOfWeekDisabled(Element e, String daysOfWeekDisabled)
}-*/;

protected native void configure(Element e, Element p, String format, int weekStart, String daysOfWeekDisabled, boolean autoClose, int startView,
int minViewMode, boolean todayBtn, boolean highlightToday, boolean keyboardNavigation, boolean forceParse, int viewSelect, String language,
int minViewMode, boolean todayBtn, boolean clearBtn, boolean highlightToday, boolean keyboardNavigation, boolean forceParse, int viewSelect, String language,
String orientation) /*-{
if (todayBtn) {
Expand All @@ -713,6 +721,7 @@ protected native void configure(Element e, Element p, String format, int weekSta
startView: startView,
minViewMode: minViewMode,
todayBtn: todayBtn,
clearBtn: clearBtn,
todayHighlight: highlightToday,
keyboardNavigation: keyboardNavigation,
forceParse: forceParse,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.gwtbootstrap3.extras.datepicker.client.ui.base.constants;

/*
* #%L
* GwtBootstrap3
* %%
* Copyright (C) 2013 - 2014 GwtBootstrap3
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

/**
* Boolean, Default: false
* <p/>
* If true, displays a clear button at the bottom of the datepicker to clear the selected date.
* If true, the "Clear" button will clear the currently selected date from the datepicker;
*
* @author Rishiraj Anand
*/
public interface HasShowClearButton {
void setShowClearButton(boolean showClearButton);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasPosition;
import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasShowMeridian;
import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasShowTodayButton;
import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasShowClearButton;
import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasStartDate;
import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasStartView;
import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasViewSelect;
Expand Down Expand Up @@ -103,7 +104,7 @@
*/
public class DateTimePickerBase extends Widget implements HasEnabled, HasReadOnly, HasId, HasResponsiveness, HasVisibility,
HasPlaceholder, HasAutoClose, HasDaysOfWeekDisabled, HasEndDate, HasForceParse, HasFormat, HasHighlightToday,
HasKeyboardNavigation, HasMaxView, HasMinuteStep, HasMinView, HasShowMeridian, HasShowTodayButton, HasStartDate,
HasKeyboardNavigation, HasMaxView, HasMinuteStep, HasMinView, HasShowMeridian, HasShowTodayButton, HasShowClearButton, HasStartDate,
HasStartView, HasViewSelect, HasWeekStart, HasDateTimePickerHandlers, HasLanguage, HasName, HasValue<Date>, HasPosition,
LeafValueEditor<Date>, HasEditorErrors<Date>, HasErrorHandler, HasValidators<Date>, HasBlankValidator<Date> {

Expand Down Expand Up @@ -149,7 +150,7 @@ public void onBlur(BlurEvent event) {
private LeafValueEditor<Date> editor;
private final ErrorHandlerMixin<Date> errorHandlerMixin = new ErrorHandlerMixin<Date>(this);
private final DatePickerValidatorMixin validatorMixin = new DatePickerValidatorMixin(this,
errorHandlerMixin.getErrorHandler());
errorHandlerMixin.getErrorHandler());

/**
* DEFAULT values
Expand All @@ -163,6 +164,7 @@ public void onBlur(BlurEvent event) {
private DateTimePickerView minView = DateTimePickerView.HOUR;
private DateTimePickerView maxView = DateTimePickerView.DECADE;
private boolean showTodayButton = false;
private boolean showClearButton = false;
private boolean highlightToday = false;
private boolean keyboardNavigation = true;
private boolean forceParse = true;
Expand Down Expand Up @@ -468,6 +470,13 @@ public void setShowTodayButton(final boolean showTodayButton) {
this.showTodayButton = showTodayButton;
}

/** {@inheritDoc} */
@Override
public void setShowClearButton(final boolean showClearButton) {
this.showClearButton = showClearButton;
}


/** {@inheritDoc} */
@Override
public void setStartDate(final Date startDate) {
Expand Down Expand Up @@ -602,7 +611,7 @@ private void setDateTimeFormat(final String format) {

/**
* Sets the format view type.
*
*
* @param formatViewType
* @see DateTimePickerFormatViewType
*/
Expand Down Expand Up @@ -676,8 +685,8 @@ protected void configure() {
this.remove(getElement());

configure(getElement(), format, formatViewType.getValue(), weekStart.getValue(), toDaysOfWeekDisabledString(daysOfWeekDisabled),
autoClose, startView.getValue(), minView.getValue(), maxView.getValue(), showTodayButton, highlightToday,
keyboardNavigation, forceParse, minuteStep, viewSelect.getValue(), showMeridian, language.getCode(), position.getPosition());
autoClose, startView.getValue(), minView.getValue(), maxView.getValue(), showTodayButton, showClearButton, highlightToday,
keyboardNavigation, forceParse, minuteStep, viewSelect.getValue(), showMeridian, language.getCode(), position.getPosition());
}

protected void execute(final String cmd) {
Expand Down Expand Up @@ -717,9 +726,9 @@ private native void setDaysOfWeekDisabled(Element e, String daysOfWeekDisabled)
}-*/;

protected native void configure(Element e, String format, String formatViewType, int weekStart,
String daysOfWeekDisabled, boolean autoClose, int startView, int minView, int maxView, boolean todayBtn,
boolean highlightToday, boolean keyboardNavigation, boolean forceParse, int minuteStep, int viewSelect,
boolean showMeridian, String language, String position) /*-{
String daysOfWeekDisabled, boolean autoClose, int startView, int minView, int maxView, boolean todayBtn, boolean clearBtn,
boolean highlightToday, boolean keyboardNavigation, boolean forceParse, int minuteStep, int viewSelect,
boolean showMeridian, String language, String position) /*-{
var that = this;
$wnd.jQuery(e).datetimepicker({
format: format,
Expand All @@ -732,6 +741,7 @@ protected native void configure(Element e, String format, String formatViewType,
minView: minView,
maxView: maxView,
todayBtn: todayBtn,
clearBtn: clearBtn,
todayHighlight: highlightToday,
keyboardNavigation: keyboardNavigation,
forceParse: forceParse,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants;

/*
* #%L
* GwtBootstrap3
* %%
* Copyright (C) 2013 - 2014 GwtBootstrap3
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

/**
* Boolean, Default: false
* <p/>
* If true, displays a clear button at the bottom of the datetimepicker to clear the current date.
* If true, the "Clear" button will clear the currently selected date from the datetimepicker;
*
* @author Rishiraj Anand
*/
public interface HasShowClearButton {
void setShowClearButton(boolean showClearButton);
}

0 comments on commit 8e42aaf

Please sign in to comment.