diff options
author | Artur Signell <artur@vaadin.com> | 2012-11-20 13:12:43 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-11-20 13:12:43 +0000 |
commit | 40e7287b82df23e9105f51b7ca086e93fb8903c5 (patch) | |
tree | 6e1bdb4b0382844d4ec170fe65b96da8a04e7ba2 /client | |
parent | 9c04958fdda8f490fc91aef19819ef9965c36e2e (diff) | |
parent | fb771475c1b94d0dca3e1cb69f87cb8d80630aad (diff) | |
download | vaadin-framework-40e7287b82df23e9105f51b7ca086e93fb8903c5.tar.gz vaadin-framework-40e7287b82df23e9105f51b7ca086e93fb8903c5.zip |
Merge "Added possibility to disable text input for PopupDateField (#6790)"
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/VPopupCalendar.java | 33 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java | 7 |
2 files changed, 40 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VPopupCalendar.java b/client/src/com/vaadin/client/ui/VPopupCalendar.java index 941978d129..c5680e3662 100644 --- a/client/src/com/vaadin/client/ui/VPopupCalendar.java +++ b/client/src/com/vaadin/client/ui/VPopupCalendar.java @@ -66,6 +66,8 @@ public class VPopupCalendar extends VTextualDate implements Field, private boolean open = false; + private boolean textFieldEnabled = true; + public VPopupCalendar() { super(); @@ -156,6 +158,34 @@ public class VPopupCalendar extends VTextualDate implements Field, } } + /** + * Checks whether the text field is enabled. + * + * @see VPopupCalendar#setTextFieldEnabled(boolean) + * @return The current state of the text field. + */ + public boolean isTextFieldEnabled() { + return textFieldEnabled; + } + + /** + * Sets the state of the text field of this component. By default the text + * field is enabled. Disabling it causes only the button for date selection + * to be active, thus preventing the user from entering invalid dates. See + * {@link http://dev.vaadin.com/ticket/6790}. + * + * @param state + */ + public void setTextFieldEnabled(boolean textFieldEnabled) { + this.textFieldEnabled = textFieldEnabled; + text.setEnabled(textFieldEnabled); + if (textFieldEnabled) { + calendarToggle.setTabIndex(-1); + } else { + calendarToggle.setTabIndex(0); + } + } + /* * (non-Javadoc) * @@ -335,6 +365,9 @@ public class VPopupCalendar extends VTextualDate implements Field, if (!parsable) { setText(previousValue); } + + // superclass sets the text field independently when building date + text.setEnabled(isEnabled() && isTextFieldEnabled()); } /** diff --git a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java index 3859a22046..1ff1e58e72 100644 --- a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java +++ b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java @@ -21,6 +21,7 @@ import java.util.Date; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.DateTimeService; import com.vaadin.client.UIDL; +import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.VCalendarPanel.FocusChangeListener; import com.vaadin.client.ui.VCalendarPanel.TimeChangeListener; import com.vaadin.client.ui.VPopupCalendar; @@ -132,6 +133,12 @@ public class PopupDateFieldConnector extends TextualDateConnector { } @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + getWidget().setTextFieldEnabled(getState().textFieldEnabled); + } + + @Override protected void setWidgetStyleName(String styleName, boolean add) { super.setWidgetStyleName(styleName, add); |