Read Only DateBox

871 views
Skip to first unread message

Craig Mitchell

unread,
Feb 20, 2012, 12:01:17 AM2/20/12
to Google Web Toolkit
Hi,

A DateBox can be set to setEnabled(false), however, it does not have a
setReadOnly(true). And calling dateBox.getTextBox().setReadOnly(true)
does not work.

This is annoying, as browsers do nasty things to the text color when
you disable the field (which CSS doesn't seem to be able to override).

Does anyone has a nice solution to having a disabled or read only
DateBox, that can have any text colour?

Thanks.

PS: As a work around, I have a DateBox and a TextBox. When I want to
disabled the DateBox, I just hide it and show the read only TextBox,
copying in the the value across like this
myTextBox.setValue(myDateDateBox.getTextBox().getValue());

Craig Mitchell

unread,
Jan 17, 2013, 5:19:38 PM1/17/13
to google-we...@googlegroups.com
Unfortunately, .getTextBox().setReadOnly(true) doesn't work, as the DatePicker still shows when clicking on the field.

However, I now realise that doing setEnabled(false) and setting some CSS, it's only IE that ignores the CSS and shows the nasty, hard to read, shadowed text.  But I say, bad luck to IE users, they should just switch to a different browser!  :-)


On Thursday, 17 January 2013 14:59:01 UTC+11, 彭振友 wrote:
.getTextBox().setReadOnly(true);
hope that help you。

Craig Mitchell

unread,
Jan 18, 2013, 12:54:45 AM1/18/13
to google-we...@googlegroups.com
Just revisited this code.  Worked out that we can override the showDatePicker method to check for read only.   You're welcome IE users!  :-)

public class MyDateBox extends DateBox {
public void setReadOnly(boolean readOnly) {
getTextBox().setReadOnly(readOnly);
}
@Override
public void showDatePicker() {
if (getTextBox().isReadOnly() == false) {
super.showDatePicker();
Reply all
Reply to author
Forward
0 new messages