Zebra API Doc

zebra.ui.TextField Class

Extends zebra.ui.Label

Text field UI component. The component is designed to enter single line, multi lines or password text. The component implement text field functionality from the scratch. It supports the following features

  • Text selection
  • Redu/Undo actions
  • Native WEB clipboard
  • Basic text navigation
  • Read-only mode

Constructor

zebra.ui.TextField

(
  • [txt]
  • [maxCol]
)

Parameters:

  • [txt] String | zebra.data.TextModel | zebra.ui.TextRender optional

    a text the text field component has to be filled. The parameter can be a simple string, text model or text render class instance.

  • [maxCol] Integer optional

    a maximal size of entered text. -1 means the size of the edited text has no length limit.

Methods

calcPreferredSize

(
  • t
)
Object

Inherited from zebra.ui.ViewPan:

Override the parent method to calculate preferred size basing on a target view.

Parameters:


Return: Object

return a target view preferred size if it is defined. The returned structure is the following: { width: {Integer}, height:{Integer} }

clearSelection

()

Clear a text selection.

drawCursor

(
  • g
)
protected

Draw the text field cursor

Parameters:

  • g 2DContext

    a 2D contextnn

getColor

() String

Inherited from zebra.ui.Label:

Get the label text color


Return: String

a zebra label color

getEndSelection

() Array

Get an ending position (row and column) of a selected text


Return: Array

a position of a selected text. First element of is a row and second column of selected text. null if there is no any selected text

getFont

() zebra.ui.Font

Inherited from zebra.ui.Label:

Get the label text font


Return: zebra.ui.Font

a zebra label font

getSelectedText

() String

Get a selected text


Return: String

a selected text

getStartSelection

() Array

Get a starting position (row and column) of a selected text


Return: Array

a position of a selected text. First element of is a row and second column of selected text. null if there is no any selected text

getTextRowColAt

(
  • x
  • y
)
Array

Compute a text column and row by the given location.

Parameters:

  • x Integer

    a x coordinate

  • y Integer

    a y coordinate


Return: Array

a text row and column as an Array object. Fist element of the array is row and the second one is column.

getValue

() String

Inherited from zebra.ui.Label:

Get the label text


Return: String

a zebra label text

hasSelection

() Boolean

Test if the text field has a selected text


Return: Boolean

true if the text field has a selected text

isFiltered

(
  • e
)
Boolean protected

Test if the given key pressed event has to be processed

Parameters:


Return: Boolean

true if the given key pressed event doesn't have be processed

remove

(
  • pos
  • size
)

Remove the specified part of edited text

Parameters:

  • pos Integer

    a start position of a removed text

  • size Integer

    a size of removed text

removeSelected

()

Remove selected text

select

(
  • startOffset
  • endOffset
)

Select the specified part of the edited text

Parameters:

  • startOffset Integer

    a start position of a selected text

  • endOffset Integer

    an end position of a selected text

setBlinking

(
  • [period]
)

Set the specified blinking period of the text field cursor

Parameters:

  • [period] Integer optional

    a text field cursor blinking period (in milliseconds), use -1 to disable cursor blinking. If the argument is not passed the default (500ms) blinking period will be applied.

setColor

(
  • c
)
chainable

Inherited from zebra.ui.Label:

Set the label text color

Parameters:

  • c String

    a text color

setCursorView

(
  • v
)

Set the cursor view. The view defines rendering of the text field cursor.

Parameters:

setEditable

(
  • b
)

Control the text field editable state

Parameters:

  • b Boolean

    true to make the text field editable

setFont

(
  • f
)
chainable

Inherited from zebra.ui.Label:

Set the label text font

Parameters:

setHint

(
  • hint
  • font
  • color
)

Set the specified hint text to be drawn with the given font and color. The hint is not-editable text that is shown in empty text field to help a user to understand which input the text field expects.

Parameters:

  • hint String

    a hint text

  • font String | zebra.ui.Font

    a font

  • color String

    a hint color

setModel

(
  • m
)

Set the text field text model

Parameters:

setPosition

(
  • p
)

Set the specified cursor position controller

Parameters:

setPSByRowsCols

(
  • r
  • c
)

Adjust the size of the text field component to be enough to place the given number of rows and columns.

Parameters:

  • r Integer

    a row of the text the height of the text field has to be adjusted

  • c Integer

    a column of the text the width of the text field has to be adjusted

setSelectionColor

(
  • c
)

Set selection color

Parameters:

  • c String

    a selection color

setValue

(
  • s
)

Inherited from zebra.ui.Label

Set the text content of the text field component

Parameters:

  • s String

    a text the text field component has to be filled

setView

(
  • v
)
chainable

Inherited from zebra.ui.ViewPan:

Set the target view to be wrapped with the UI component

Parameters:

  • v zebra.ui.View | Function

    a view or a rendering view "paint(g,x,y,w,h,c)" function

write

(
  • pos
  • s
)

Insert the specified text into the edited text at the given position

Parameters:

  • pos Integer

    a start position of a removed text

  • s String

    a text to be inserted

Attributes

blinkigPeriod

Number readonly

Specify the text field cursor blinking period in milliseconds. -1 means no blinkable cursor

Default: -1

curView

zebra.ui.View readonly

Cursor view

isEditable

Boolean readonly

Indicate if the text field is editable

Default: true

selectionColor

String readonly

Selection color

view

zebra.ui.View readonly

Inherited from zebra.ui.ViewPan:

Reference to a view that the component visualize

Default: null