mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-02 19:27:57 +08:00
DateField bugs with Vaadin 7 #PL-2084
This commit is contained in:
parent
dde8e1ff51
commit
c434f29dde
@ -7,7 +7,6 @@
|
||||
package com.haulmont.cuba.web.toolkit.ui.client.datefield;
|
||||
|
||||
import com.google.gwt.event.dom.client.*;
|
||||
import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.textfield.CubaMaskedTextFieldWidget;
|
||||
import com.vaadin.client.BrowserInfo;
|
||||
import com.vaadin.client.ui.VPopupCalendar;
|
||||
@ -24,7 +23,7 @@ public class CubaDateFieldWidget extends VPopupCalendar
|
||||
|
||||
private static final String CLASSNAME = "cuba-datefield";
|
||||
|
||||
private static final String MASKED_FIELD_CLASS = "cuba-datefield-masked-input";
|
||||
private static final String EMPTY_FIELD_CLASS = "cuba-datefield-empty";
|
||||
|
||||
private static final char PLACE_HOLDER = '_';
|
||||
|
||||
@ -39,6 +38,7 @@ public class CubaDateFieldWidget extends VPopupCalendar
|
||||
private List<CubaMaskedTextFieldWidget.Mask> maskTest;
|
||||
|
||||
public CubaDateFieldWidget() {
|
||||
setStylePrimaryName(CLASSNAME);
|
||||
setStyleName(CLASSNAME);
|
||||
|
||||
text.addKeyPressHandler(this);
|
||||
@ -49,10 +49,10 @@ public class CubaDateFieldWidget extends VPopupCalendar
|
||||
|
||||
@Override
|
||||
public void setText(String value) {
|
||||
if (value.equals(nullRepresentation) || value.equals("")) {
|
||||
text.getElement().addClassName(MASKED_FIELD_CLASS);
|
||||
if (value == null || value.equals(nullRepresentation) || value.equals("")) {
|
||||
text.getElement().addClassName(EMPTY_FIELD_CLASS);
|
||||
} else {
|
||||
text.getElement().removeClassName(MASKED_FIELD_CLASS);
|
||||
text.getElement().removeClassName(EMPTY_FIELD_CLASS);
|
||||
}
|
||||
if ("".equals(value) && !readonly) {
|
||||
setMask(mask);
|
||||
@ -116,7 +116,7 @@ public class CubaDateFieldWidget extends VPopupCalendar
|
||||
if (isReadonly())
|
||||
return;
|
||||
if (!dateBuilder.toString().equals(nullRepresentation)) {
|
||||
text.getElement().removeClassName(MASKED_FIELD_CLASS);
|
||||
text.getElement().removeClassName(EMPTY_FIELD_CLASS);
|
||||
}
|
||||
for (int i = 0; i < dateBuilder.length(); i++) {
|
||||
char c = dateBuilder.charAt(i);
|
||||
|
@ -21,17 +21,17 @@ public class CubaMaskedTextFieldWidget extends VTextField {
|
||||
|
||||
public static final String CLASSNAME = "cuba-maskedfield";
|
||||
|
||||
private static final String MASKED_FIELD_CLASS = "cuba-masked-input";
|
||||
protected static final String EMPTY_FIELD_CLASS = "cuba-maskedfield-empty";
|
||||
|
||||
private static final char PLACE_HOLDER = '_';
|
||||
protected static final char PLACE_HOLDER = '_';
|
||||
|
||||
private StringBuilder valueBuilder;
|
||||
protected StringBuilder valueBuilder;
|
||||
|
||||
private String nullRepresentation;
|
||||
protected String nullRepresentation;
|
||||
|
||||
protected String mask;
|
||||
|
||||
private List<Mask> maskTest;
|
||||
protected List<Mask> maskTest;
|
||||
|
||||
public CubaMaskedTextFieldWidget() {
|
||||
setStylePrimaryName(CLASSNAME);
|
||||
@ -44,11 +44,11 @@ public class CubaMaskedTextFieldWidget extends VTextField {
|
||||
addBlurHandler(inputHandler);
|
||||
}
|
||||
|
||||
private void updateCursor(int pos) {
|
||||
protected void updateCursor(int pos) {
|
||||
setCursorPos(getNextPos(pos));
|
||||
}
|
||||
|
||||
private int getNextPos(int pos) {
|
||||
protected int getNextPos(int pos) {
|
||||
while (++pos < maskTest.size() && maskTest.get(pos) == null) {
|
||||
}
|
||||
return pos;
|
||||
@ -63,12 +63,15 @@ public class CubaMaskedTextFieldWidget extends VTextField {
|
||||
}
|
||||
|
||||
public void setText(String value) {
|
||||
if (value == null || "".equals(value))
|
||||
value = nullRepresentation;
|
||||
|
||||
valueBuilder = new StringBuilder(value);
|
||||
if (value.equals(nullRepresentation)) {
|
||||
getElement().addClassName(MASKED_FIELD_CLASS);
|
||||
} else {
|
||||
getElement().removeClassName(MASKED_FIELD_CLASS);
|
||||
}
|
||||
if (value.equals(nullRepresentation))
|
||||
getElement().addClassName(EMPTY_FIELD_CLASS);
|
||||
else
|
||||
getElement().removeClassName(EMPTY_FIELD_CLASS);
|
||||
|
||||
super.setText(value);
|
||||
}
|
||||
|
||||
@ -120,6 +123,11 @@ public class CubaMaskedTextFieldWidget extends VTextField {
|
||||
setText(valueBuilder.toString());
|
||||
}
|
||||
|
||||
protected void setRawCursorPosition(int pos) {
|
||||
if (pos >=0 && pos <= maskTest.size())
|
||||
setCursorPos(pos);
|
||||
}
|
||||
|
||||
public interface Mask {
|
||||
boolean isValid(char c);
|
||||
|
||||
@ -265,34 +273,37 @@ public class CubaMaskedTextFieldWidget extends VTextField {
|
||||
return;
|
||||
if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) {
|
||||
int pos = getPreviousPos(getCursorPos());
|
||||
Mask m = maskTest.get(pos);
|
||||
if (m != null) {
|
||||
valueBuilder.setCharAt(pos, PLACE_HOLDER);
|
||||
setValue(valueBuilder.toString());
|
||||
if (pos < maskTest.size() && pos >= 0) {
|
||||
Mask m = maskTest.get(pos);
|
||||
if (m != null) {
|
||||
valueBuilder.setCharAt(pos, PLACE_HOLDER);
|
||||
setValue(valueBuilder.toString());
|
||||
}
|
||||
setCursorPos(pos);
|
||||
}
|
||||
setCursorPos(pos);
|
||||
event.preventDefault();
|
||||
} else if (event.getNativeKeyCode() == KeyCodes.KEY_DELETE) {
|
||||
int pos = getCursorPos();
|
||||
|
||||
Mask m = maskTest.get(pos);
|
||||
if (m != null) {
|
||||
valueBuilder.setCharAt(pos, PLACE_HOLDER);
|
||||
setValue(valueBuilder.toString());
|
||||
if (pos < maskTest.size() && pos >= 0) {
|
||||
Mask m = maskTest.get(pos);
|
||||
if (m != null) {
|
||||
valueBuilder.setCharAt(pos, PLACE_HOLDER);
|
||||
setValue(valueBuilder.toString());
|
||||
}
|
||||
updateCursor(pos);
|
||||
}
|
||||
updateCursor(pos);
|
||||
event.preventDefault();
|
||||
} else if (event.getNativeKeyCode() == KeyCodes.KEY_RIGHT) {
|
||||
setCursorPos(getNextPos(getCursorPos()));
|
||||
setRawCursorPosition(getNextPos(getCursorPos()));
|
||||
event.preventDefault();
|
||||
} else if (event.getNativeKeyCode() == KeyCodes.KEY_LEFT) {
|
||||
setCursorPos(getPreviousPos(getCursorPos()));
|
||||
setRawCursorPosition(getPreviousPos(getCursorPos()));
|
||||
event.preventDefault();
|
||||
} else if (event.getNativeKeyCode() == KeyCodes.KEY_HOME || event.getNativeKeyCode() == KeyCodes.KEY_UP) {
|
||||
setCursorPos(getPreviousPos(0));
|
||||
setRawCursorPosition(getPreviousPos(0));
|
||||
event.preventDefault();
|
||||
} else if (event.getNativeKeyCode() == KeyCodes.KEY_END || event.getNativeKeyCode() == KeyCodes.KEY_DOWN) {
|
||||
setCursorPos(getPreviousPos(getValue().length()) + 1);
|
||||
setRawCursorPosition(getPreviousPos(getValue().length()) + 1);
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
@ -301,11 +312,12 @@ public class CubaMaskedTextFieldWidget extends VTextField {
|
||||
public void onFocus(FocusEvent event) {
|
||||
if (isReadOnly())
|
||||
return;
|
||||
if (getValue().isEmpty())
|
||||
if (getValue().isEmpty()) {
|
||||
setMask(mask);
|
||||
else
|
||||
setCursorPos(getPreviousPos(0));
|
||||
|
||||
} else {
|
||||
int previousPos = getPreviousPos(0);
|
||||
setRawCursorPosition(previousPos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,7 +145,7 @@ public class WebTimeField extends WebAbstractField<CubaMaskedTextField> implemen
|
||||
try {
|
||||
return (T) new SimpleDateFormat(timeFormat).parse((String) value);
|
||||
} catch (ParseException e) {
|
||||
log.warn("Unable to parse value of component " + getId() + "\n" + e.getMessage());
|
||||
log.debug("Unable to parse value of component " + getId() + "\n" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
@ -247,7 +247,7 @@ public class WebTimeField extends WebAbstractField<CubaMaskedTextField> implemen
|
||||
component.setComponentError(null);
|
||||
return date;
|
||||
} catch (Exception e) {
|
||||
log.warn("Unable to parse value of component " + getId() + "\n" + e.getMessage());
|
||||
log.debug("Unable to parse value of component " + getId() + "\n" + e.getMessage());
|
||||
component.setComponentError(new UserError("Invalid value"));
|
||||
return null;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ package com.haulmont.cuba.web.toolkit.ui;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.datefield.CubaDateFieldState;
|
||||
import com.vaadin.data.Validator;
|
||||
import com.vaadin.data.util.converter.Converter;
|
||||
import com.vaadin.shared.communication.SharedState;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
|
@ -13,6 +13,8 @@ import com.vaadin.shared.ui.datefield.PopupDateFieldState;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CubaDateFieldState extends PopupDateFieldState {
|
||||
|
||||
{
|
||||
primaryStyleName = "cuba-datefield";
|
||||
}
|
||||
public String dateMask = "";
|
||||
}
|
@ -6,13 +6,19 @@
|
||||
|
||||
// Version: $Id$
|
||||
|
||||
@mixin havana-datefield($primaryStyleName : v-datefield) {
|
||||
@mixin havana-datefield($primaryStyleName : cuba-datefield) {
|
||||
@include base-datefield($primaryStyleName);
|
||||
|
||||
.#{$primaryStyleName} {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.#{$primaryStyleName}-popupcalendar {
|
||||
padding-right: 25px;
|
||||
input.#{$primaryStyleName}-empty {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
input.#{$primaryStyleName}-empty:focus {
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.#{$primaryStyleName}-button {
|
||||
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
// Version: $Id$
|
||||
|
||||
@mixin havana-maskedfield($primaryStyleName: cuba-maskedfield) {
|
||||
.v-ui,
|
||||
.v-window {
|
||||
input.#{$primaryStyleName}-empty {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
input.#{$primaryStyleName}-empty:focus {
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@
|
||||
@import "components/fieldgroup/fieldgroup";
|
||||
@import "components/splitpanel/splitpanel";
|
||||
@import "components/grouptable/grouptable";
|
||||
@import "components/maskedfield/maskedfield";
|
||||
@import "components/multiupload/multiupload";
|
||||
@import "components/contextmenu/contextmenu";
|
||||
@import "components/popupbutton/popupbutton";
|
||||
@ -71,6 +72,7 @@
|
||||
@include havana-fieldgroup;
|
||||
@include havana-popupbutton;
|
||||
@include havana-contextmenu;
|
||||
@include havana-maskedfield;
|
||||
@include havana-notification;
|
||||
@include havana-filterselect;
|
||||
@include havana-orderedlayout;
|
||||
|
Loading…
Reference in New Issue
Block a user