The text
field is used to represent text within a form.
Title | Single-Line Text |
Description | Text field for single-line text. |
JSON Schema Type(s) | string |
Field Type | text |
Base Field Type | None |
Property | Type | Default | Description |
---|---|---|---|
default | any | The default value to be assigned for this property. If the data for the field is empty or not provided, this default value will be plugged in for you. Specify a default value when you want to pre-populate the field's value ahead of time. | |
dependencies | array | List of property dependencies. | |
description | string | Detailed description of the property. | |
disallow | array | List of disallowed values for the property. | |
enum | array | List of specific values for this property | |
format | string | Data format of the property. | |
maxLength | number | Maximum length of the property value. | |
minLength | number | Minimal length of the property value. | |
pattern | string | Regular expression for the property value. | |
readonly | boolean | Indicates that the field is read-only. A read-only field cannot have it's value changed. Read-only fields render in a grayed-out or disabled control. If the field is rendered using a view with the displayReadonly attribute set to false, the read-only field will not appear. | |
required | boolean | Indicates whether the field's value is required. If set to true, the field must take on a valid value and cannnot be left empty or unassigned. | |
title | string | Short description of the property. | |
type | string | string | Data type of the property. |
Property | Type | Default | Description |
---|---|---|---|
allowOptionalEmpty | Allows this non-required field to validate when the value is empty | ||
autocomplete | string | Allows you to specify the autocomplete attribute for the underlying input control whether or not field should have autocomplete enabled. | |
data | object | Allows you to specify a key/value map of data attributes that will be added as DOM attribuets for the underlying input control. The data attributes will be added as data-{name}='{value}'. | |
disabled | boolean | Field will be disabled if true. | |
disallowEmptySpaces | boolean | Whether to disallow the entry of empty spaces in the text | |
disallowOnlyEmptySpaces | boolean | Whether to disallow the entry of only empty spaces in the text | |
fieldClass | string | Specifies one or more CSS classes that should be applied to the dom element for this field once it is rendered. Supports a single value, comma-delimited values, space-delimited values or values passed in as an array. | |
focus | checkbox | true | If true, the initial focus for the form will be set to the first child element (usually the first field in the form). If a field name or path is provided, then the specified child field will receive focus. For example, you might set focus to 'name' (selecting the 'name' field) or you might set it to 'client/name' which picks the 'name' field on the 'client' object. |
form | object | Options for rendering the FORM tag. | |
helper | string | Field help message. | |
helpers | array | An array of field help messages. Each message will be displayed on it's own line. | |
helpersPosition | string | below | Defines the placement location of the helper text relative to the control (either 'above' or 'below') |
hidden | boolean | Field will be hidden if true. | |
hideInitValidationError | boolean | Hide initial validation errors if true. | |
id | string | Unique field id. Auto-generated if not provided. | |
inputType | string | Allows for the override of the underlying HTML5 input type. If not specified, an assumed value is provided based on the kind of input control (i.e. 'text', 'date', 'email' and so forth) | |
label | string | Field label. | |
maskString | string | Expression for the field mask. Field masking will be enabled if not empty. | |
name | string | Field Name. | |
optionLabels | array | An array of string labels for items in the enum array | |
placeholder | string | Field placeholder. | |
readonly | boolean | Field will be readonly if true. | |
showMessages | boolean | true | Display validation messages if true. |
size | number | 40 | Field size. |
sort | function | Defines an f(a,b) sort function for the array of enumerated values [{text, value}]. This is used to sort enum and optionLabels as well as results that come back from any data sources (for select and radio controls). By default the items are sorted alphabetically. Don't apply any sorting if false. | |
type | string | text | Field type. |
typeahead | Provides configuration for the $.typeahead plugin if it is available. For full configuration options, see: https://github.com/twitter/typeahead.js | ||
validate | boolean | true | Field validation is required if true. |
view | string | Allows for this field to be rendered with a different view (such as 'display' or 'create') |
A simple example of using Alpaca with nothing more than a string of text. Alpaca looks at your data and determines that it
is a string. It then looks for a suitable candidate for representing a string and it decides to use the text
field.
A more developed example that specifies not only the data but also the schema and options. In this example, we intentionally set the data to something that is invalid. The schema specifies that the maximum length of the allowed value is 8 characters. Our value exceeds that and so we receive a message straight away indicating this problem.
Text field with data, schema, options and view parameters. The view parameter is for injecting additional styles to make the field label float to the left of the text field.
Text field with a mask. This feature is based on Josh Bush's Masked Input Plugin. It allows a user to more easily enter fixed width input where you would like them to enter the data in a certain format (dates,phone numbers, etc). The maskString parameter supports following predefined characters:
Text field with an event listener option that listens to keypress event and then prints out your input in an outside div in reverse order.
Displays a text field using a display-only view. The text field simply prints out and is not editable.
This example uses $.typeahead auto-completion with a function to provide lookup values.
The config
block defines the first argument into the typeahead plugin.
The datasets
block defines the second argument into the typeahead plugin.
Simple configuration for $.typeahead auto-completion of the field value based on locally provided values.
By convention, the source
setting is a function that provides the dataset for a given query (see the typeahead documentation).
To make things easier, we also accept an object with two fields - type
and source
.
If type
is local
, then an array can be passed in via source
. The array should be either simple
strings or an array of objects with the structure {'value': ''}
.
If type
is remote
, then the source is a remote URL. This should hand back an array of objects with the structure {'value': ''}
.
If type
is prefetch
, the source is a prefetch URL. This should hand back an array of objects with the structure {'value': ''}
.
Here, for fun, we register a change
event handler that pretties up a little box so we can see what the
CSS color looks like.
This example uses $.typeahead auto-completion with a remote data source. Auto-completion is provided for names of cloud computing companies. It also uses Hogan.js to assist with template driven rendering of the drop-down list.
The remote values are retrieved from a PHP script that accepts the input text as a query parameter. It uses this to perform a simple comparison. In your own script, you'll likely query a database or connect to a web service to produce matches.
This example uses the placeholder
option to set up the placeholder text
for a text field.
This example constrains the entered text value, forcing it to be at minimum 3 and at most 25. This not only runs validation checks but also enforces some UI behavior.
This also shows how many characters are left for maxLength
as you type.
A text field with disallowed values.
A text field with autocomplete.
A text with field with disallowEmptySpaces
set to true
. This prevents the entry of spaces.
This is useful for things like username entry fields, as configured below.
A simple example of using Alpaca with nothing more than a string of text. Alpaca looks at your data and determines that it
is a string. It then looks for a suitable candidate for representing a string and it decides to use the text
field.