Google Apps Script

Class DateBox

A text box that shows a DatePicker when the user focuses on it.

Here is an example of how to use this widget:

 
function doGet() {
   var app = UiApp.createApplication();
   var handler = app.createServerHandler("change");
   var dateBox = app.createDateBox().addValueChangeHandler(handler).setId("datebox");
   app.add(dateBox);
   return app;
 }

 function change(eventInfo) {
   var app = UiApp.getActiveApplication();
   app.add(app.createLabel("The value of the date box changed to " +
       eventInfo.parameter.datebox));
    return app;
  }
 

Internally, UiApp widgets are built on top of the Google Web Toolkit, and it can sometimes be helpful to look at the GWT documentation directly. You can find the DateBox documentation here.

Methods

MethodReturn typeBrief description
addStyleDependentName(styleName)DateBoxSets the dependent style name of this DateBox.
addStyleName(styleName)DateBoxAdds a style name to this DateBox.
addValueChangeHandler(handler)DateBoxAdd a handler for value change events.
getId()StringReturns the id that has been assigned to this object.
getTag()StringGets the text tag of this DateBox.
getType()StringGets the type of this object.
hideDatePicker()DateBoxHide the date picker.
setEnabled(enabled)DateBoxSets whether the DateBox is enabled.
setFireEventsForInvalid(fireEvents)DateBoxSets whether value changed events are fired for invalid or empty input in the box.
setFocus(focus)DateBoxExplicitly focus/unfocus this DateBox.
setFormat(dateTimeFormat)DateBoxSets the format used to control formatting and parsing of dates in this DateBox.
setHeight(height)DateBoxSets the height of this DateBox.
setId(id)DateBoxSets the id of this DateBox.
setName(name)DateBoxSets the name of the DateBox, which is how it will be referred to when used in a FormPanel or as a callback element on an event handler.
setPixelSize(width, height)DateBoxSets the size of this DateBox in pixels.
setSize(width, height)DateBoxSets the size of this DateBox.
setStyleAttribute(attribute, value)DateBoxSets one of this DateBox's style attributes to a new value.
setStyleAttributes(attributes)DateBoxSets this DateBox's style attributes.
setStyleName(styleName)DateBoxSets the style name of this DateBox.
setStylePrimaryName(styleName)DateBoxSets the primary style name of this DateBox.
setTabIndex(index)DateBoxSets the DateBox's position in the tab index.
setTag(tag)DateBoxSets the text tag of this DateBox.
setTitle(title)DateBoxSets the hover title of this DateBox.
setValue(date)DateBoxSets the date shown by this DateBox.
setVisible(visible)DateBoxSets whether this DateBox is visible.
setWidth(width)DateBoxSets the width of this DateBox.
showDatePicker()DateBoxParses the current DateBox's value and shows that date.

Detailed documentation

addStyleDependentName(styleName)

Sets the dependent style name of this DateBox.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

DateBox — the DateBox itself, useful for chaining.


addStyleName(styleName)

Adds a style name to this DateBox.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

DateBox — the DateBox itself, useful for chaining.


addValueChangeHandler(handler)

Add a handler for value change events.

Note that you can have multiple handlers for the same event on the same widget. They will be called in the order that they were added to the widget, although ServerHandlers may appear to happen simultaneously.

The handler passes back some information to the server about what happened. This information can be accessed as follows:

 
function doGet() {
   var app = UiApp.createApplication();
   var textBox = app.createTextBox();
   var handler = app.createServerHandler("handlerFunction");
   textBox.addValueChangeHandler(handler);
   app.add(textBox);
   return app;
 }

 function handlerFunction(eventInfo) {
   var parameter = eventInfo.parameter;
   // the type of event, in this case "valueChange".
   var eventType = parameter.eventType;
   // the id of the widget that fired this event.
   var source = parameter.source;
 }
 
In addition, the values of certain widgets can be sent up with the event as well as "callback elements." See the documentation of ServerHandler for more information.

Parameters

NameTypeDescription
handlerHandlerthe handler to execute when the event occurs. This can be a ClientHandler or a ServerHandler.

Return

DateBox — the DateBox itself, useful for chaining.


getId()

Returns the id that has been assigned to this object.

This can be used in conjunction with app.getElementById() to retrieve a reference to this object.

Return

String — the id that has been assigned to this object


getTag()

Gets the text tag of this DateBox.

Return

String — the text tag.


getType()

Gets the type of this object.

Return

String — the object type


hideDatePicker()

Hide the date picker.

Return

DateBox — the DateBox itself, useful for chaining.


setEnabled(enabled)

Sets whether the DateBox is enabled.

Parameters

NameTypeDescription
enabledBooleanwhether the DateBox should be enabled or disabled.

Return

DateBox — the DateBox itself, useful for chaining.


setFireEventsForInvalid(fireEvents)

Sets whether value changed events are fired for invalid or empty input in the box. If this is false, which is the default, value change events will only be fired for valid dates selected from the picker or typed into the box. If this is true, a value change event will be fired when the box is changed from a valid date string to an invalid or empty string, with the date value in the event set to null. No value change event will be fired if the box is changed from one invalid string to another, since all invalid or empty dates are equivalently treated as null dates.

Parameters

NameTypeDescription
fireEventsBooleanif set to true, value change events will be fired when the box is changed from a valid date string to an invalid or empty string, with the date value in the event set to null.

Return

DateBox — the DateBox itself, useful for chaining.


setFocus(focus)

Explicitly focus/unfocus this DateBox.

Only one widget can have focus at a time, and the widget that does will receive all keyboard events.

Parameters

NameTypeDescription
focusBooleanwhether the DateBox should have the current focus.

Return

DateBox — the DateBox itself, useful for chaining.


setFormat(dateTimeFormat)

Sets the format used to control formatting and parsing of dates in this DateBox.

If this DateBox is not empty, the contents will be replaced with current contents in the new format.

Parameters

NameTypeDescription
dateTimeFormatDateTimeFormatthe desired format such as UiApp.DateTimeFormat.DATE_TIME_FULL.

Return

DateBox — the DateBox itself, useful for chaining.


setHeight(height)

Sets the height of this DateBox.

Parameters

NameTypeDescription
heightStringthe new height in any CSS unit such as "10px" or "50%".

Return

DateBox — the DateBox itself, useful for chaining.


setId(id)

Sets the id of this DateBox.

Parameters

NameTypeDescription
idStringthe new id, which can be used to retrieve the DateBox from app.getElementById(id).

Return

DateBox — the DateBox itself, useful for chaining.


setName(name)

Sets the name of the DateBox, which is how it will be referred to when used in a FormPanel or as a callback element on an event handler.

Parameters

NameTypeDescription
nameStringthe new name.

Return

DateBox — the DateBox itself, useful for chaining.


setPixelSize(width, height)

Sets the size of this DateBox in pixels.

Parameters

NameTypeDescription
widthIntegerthe new width in pixels.
heightIntegerthe new height in pixels.

Return

DateBox — the DateBox itself, useful for chaining.


setSize(width, height)

Sets the size of this DateBox.

Parameters

NameTypeDescription
widthStringthe new width in any CSS unit such as "10px" or "50%".
heightStringthe new height in any CSS unit such as "10px" or "50%".

Return

DateBox — the DateBox itself, useful for chaining.


setStyleAttribute(attribute, value)

Sets one of this DateBox's style attributes to a new value. Valid attributes are listed here; the values for each attribute are the same as those available in CSS style sheets.

 
// Change the widget's background to black and text color to green.
 widget.setStyleAttribute("background", "black")
     .setStyleAttribute("color", "green");
 

Parameters

NameTypeDescription
attributeStringthe CSS attribute, in camel-case ("fontSize", not "font-size"), as listed here
valueStringthe CSS value

Return

DateBox — the DateBox itself, useful for chaining.


setStyleAttributes(attributes)

Sets this DateBox's style attributes. This is a convenience method that is equivalent to calling setStyleAttribute with every key/value pair in the attributes object. Valid attributes are listed here; the values for each attribute are the same as those available in CSS style sheets.

 
// Change the widget's background to black and text color to green.
 widget.setStyleAttributes({background: "black", color: "green"});
 

Parameters

NameTypeDescription
attributesObjectan object of key/value pairs for the CSS attributes and values to set; valid attributes are listed here

Return

DateBox — the DateBox itself, useful for chaining.


setStyleName(styleName)

Sets the style name of this DateBox.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

DateBox — the DateBox itself, useful for chaining.


setStylePrimaryName(styleName)

Sets the primary style name of this DateBox.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

DateBox — the DateBox itself, useful for chaining.


setTabIndex(index)

Sets the DateBox's position in the tab index.

If more than one widget has the same tab index, each such widget will receive focus in an arbitrary order. Setting the tab index to -1 will cause this widget to be removed from the tab order.

Parameters

NameTypeDescription
indexIntegerthe new tab index.

Return

DateBox — the DateBox itself, useful for chaining.


setTag(tag)

Sets the text tag of this DateBox.

Parameters

NameTypeDescription
tagStringthe new text tag, which can be anything you wish to store with the widget.

Return

DateBox — the DateBox itself, useful for chaining.


setTitle(title)

Sets the hover title of this DateBox.

Not all browsers will show this.

Parameters

NameTypeDescription
titleStringthe hover title.

Return

DateBox — the DateBox itself, useful for chaining.


setValue(date)

Sets the date shown by this DateBox.

Parameters

NameTypeDescription
dateDatethe new date value.

Return

DateBox — the DateBox itself, useful for chaining.


setVisible(visible)

Sets whether this DateBox is visible.

Parameters

NameTypeDescription
visibleBooleanwhether this DateBox should be visible or not.

Return

DateBox — the DateBox itself, useful for chaining.


setWidth(width)

Sets the width of this DateBox.

Parameters

NameTypeDescription
widthStringthe new width in any CSS unit such as "10px" or "50%".

Return

DateBox — the DateBox itself, useful for chaining.


showDatePicker()

Parses the current DateBox's value and shows that date.

Return

DateBox — the DateBox itself, useful for chaining.

Deprecated methods


Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.