TextInput

TextInput

Creates a single line input field for entering text.

Constructor

# new TextInput(parent, x, y, text, defaultHandler)

Constructor
Parameters:
Name Type Description
parent HTMLElement The element to add this text input to.
x number The x position of the text input. Default 0.
y number The y position of the text input. Default 0.
text string The initial text to display in the text input. Default empty string.
defaultHandler function A function that will handle the "input" event.
Example
const panel = new Panel(document.body, 20, 20, 200, 200);
new TextInput(panel, 20, 20, "Hello", event => console.log(event.target.text));

Extends

Classes

TextInput

Members

# enabled

Sets and gets whether or not this component is enabled. Non-enabled components will be faded out and not respond to events.
Overrides:

# height

Sets and gets the height of this component.
Overrides:

# maxLength

Gets and sets the maximum length of the string that can be typed into the input.

# text

Gets and sets the text in the input.

# width

Sets and gets the width of this component.
Overrides:

# x

Sets and gets the x position of this component.
Overrides:

# y

Sets and gets the y position of this component.
Overrides:

Methods

# addHandler(handler)

Adds a handler function for the "input" event on this component.
Parameters:
Name Type Description
handler function A function that will handle the "input" event.
Returns:
This instance, suitable for chaining.

# bind(target, prop)

Automatically changes the value of a property on a target object with the main value of this component changes.
Parameters:
Name Type Description
target object The target object to change.
prop string The string name of a property on the target object.
Returns:
This instance, suitable for chaining.

# getEnabled()

Gets whether the component is enabled.
Returns:
Whether or not the component is enabled.

# getHeight()

Gets the height of the component.
Overrides:
Returns:
The height of the component.

# getMaxLength()

Returns:
the maximum number of characters that can be entered in this text input.

# getText()

Returns:
the text in the input.

# getWidth()

Gets the width of the component.
Overrides:
Returns:
The width of the component.

# getX()

Gets the x position of the component.
Overrides:
Returns:
The x position of the component.

# getY()

Gets the y position of the component.
Overrides:
Returns:
The y position of the component.

# move(x, y)

Moves the component to a specified position.
Parameters:
Name Type Description
x number The new x position of the component.
y number The new y position of the component.
Overrides:
Returns:
This instance, suitable for chaining.

# rotate(rad)

Rotates the component.
Parameters:
Name Type Description
rad number The number of radians to rotate the component by.
Overrides:
Returns:
This instance, suitable for chaining.

# rotateDeg(deg)

Rotates the component.
Parameters:
Name Type Description
deg number The number of degrees to rotate the component by.
Overrides:
Returns:
This instance, suitable for chaining.

# setEnabled(enabled)

Sets the enabled state of this component.
Parameters:
Name Type Description
enabled boolean Whether or not the component will be enabled.
Returns:
This instance, suitable for chaining.

# setHeight(height)

Sets the height of this component.
Parameters:
Name Type Description
height number The height of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setMaxLength(maxLength)

Sets the maximum number of characters in this text input.
Parameters:
Name Type Description
maxLength number The max number of chars.
Returns:
This instance, suitable for chaining.

# setSize(w, h)

Sizes the component.
Parameters:
Name Type Description
w number The new width of the component.
h number The new height of the component.
Overrides:
Returns:
This instance, suitable for chaining.

# setText(text)

Sets the text of this text input.
Parameters:
Name Type Description
text string The text of this text input.
Returns:
This instance, suitable for chaining.

# setWidth(width)

Sets the width of this component.
Parameters:
Name Type Description
width number The width of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setX(x)

Sets the x position of this component.
Parameters:
Name Type Description
x number The x position of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setY(y)

Sets the y position of this component.
Parameters:
Name Type Description
y number The y position of this component.
Overrides:
Returns:
this instance, suitable for chaining.