Class

Field

kiss.ui.Field(config)

The Field derives from Component.

Build an input (text, number, date) or a textarea field with a label.

Constructor

# new Field(config)

Its a Custom Web Component. Do not use the constructor directly with the new keyword. Instead, use one of the 3 following methods:

Create the Web Component and call its init method:

const myField = document.createElement("a-field").init(config)

Or use a shorthand to create one the various field types:

const myText = createTextField({
  label: "I'm a text field"
})

const myTextArea = createTextareaField({
  label: "I'm a long text field",
  cols: 100,
  rows: 10
})

const myNumber = createNumberField({
  label: "I'm a number field",
  value: 250,
  min: 0
})

const myDate = createDateField({
  label: "I'm a date field",
  value: new Date()
})

// You can also use the generic constructor, but then you'll have to specify the field type in the config, like this:
const myText = createField({
  type: "number", // <= Field type, which can be: text | textarea | number | date
  label: "foo",
  value: 123
})

Or directly declare the config inside a container component:

const myPanel = createPanel({
  title: "My panel",
  items: [
      {
          type: "text",
          label: "I'm a text"
      },
      {
          type: "number":
          label: "I'm a number"
      }
  ]
})
myPanel.render()
Parameters:
Name Type Attributes Description
config object
type string

text | textarea | number | date | password

value * <optional>

Default value

label string <optional>
labelWidth * <optional>
fieldWidth * <optional>
fieldHeight * <optional>
fieldPadding * <optional>
fieldFlex number <optional>
fontSize * <optional>
lineHeight * <optional>
textAlign string <optional>

left | right

labelPosition string <optional>

left | right | top | bottom

labelAlign string <optional>

left | right

labelFlex number <optional>
formula string <optional>

For computed fields only

validationType string <optional>

Pre-built validation type: alpha | alphanumeric | email | url | ip

validationRegex string <optional>

Regexp

validationFunction function <optional>

Async function that must return true if the value is valid, false otherwise

validationMessage string <optional>

TODO

placeholder string <optional>
autocomplete boolean <optional>

Set "off" to disable

minLength number <optional>
maxLength number <optional>
maxHeight number <optional>
readOnly boolean <optional>
disabled boolean <optional>
required boolean <optional>
draggable boolean <optional>
autocomplete boolean <optional>

set to "off" to disable native browser autocomplete feature

min string <optional>

(for number only)

max string <optional>

(for number only)

precision number <optional>

(for number only)

margin string <optional>
padding string <optional>
fontFamily string <optional>

Font used for the input field

rows boolean <optional>

For textarea only

cols boolean <optional>

For textarea only

autoGrow boolean <optional>

For textarea only

display string <optional>

flex | inline flex

overflow string <optional>
border string <optional>
borderStyle string <optional>
borderWidth string <optional>
borderColor string <optional>
borderRadius string <optional>
width string | number <optional>
height string | number <optional>

View Source client/ui/fields/field.js, line 73

this

Generated markup

For all input fields:

<a-field class="a-field a-field">
 <label class="field-label"></label>
 <input type="text|number|date" class="field-input"></input>
</a-field>

For textarea:

<a-field class="a-field">
 <span class="field-label"></span>
 <textarea class="field-input"></textarea>
</a-field>

Methods

# blur()

Unset the focus of the input field

View Source client/ui/fields/field.js, line 630

this

# focus()

Give focus to the input field

View Source client/ui/fields/field.js, line 620

this

# getDataType() → {string}

Get the data type of a field, depending on its configuration: text => text number => number date => date textarea => text password => text summary => data type of the foreign field lookup => data type of the foreign field

View Source client/ui/fields/field.js, line 501

The field data type: "text" | "number" | "date"

string

# getLabel() → {string}

Get the field label

View Source client/ui/fields/field.js, line 528

string

# getLabelPosition() → {string}

Get the label position

View Source client/ui/fields/field.js, line 573

"left" | "right" | "top"

string

# getValue() → {string|number|date}

Get the field value.

View Source client/ui/fields/field.js, line 479

  • The field value
string | number | date

# resetFocus()

Reset the focus

View Source client/ui/fields/field.js, line 638

# setDisplayMode(displayModeopt)

Change the field default display mode

Parameters:
Name Type Attributes Default Description
displayMode string <optional>
flex

"flex" (default) | "inline-flex"

View Source client/ui/fields/field.js, line 611

# setFieldWidth(width)

Set the input field width

Parameters:
Name Type Description
width *

View Source client/ui/fields/field.js, line 550

this

# setInvalid()

Change the style when the field is invalid

View Source client/ui/fields/field.js, line 659

this

# setLabel(newLabel)

Set the field label

Parameters:
Name Type Description
newLabel string

View Source client/ui/fields/field.js, line 515

this

# setLabelPosition(position)

Set label position

Parameters:
Name Type Description
position string

"left" (default) | "right" | "top" | "bottom"

View Source client/ui/fields/field.js, line 583

this

# setLabelWidth(width)

Set the label width

Parameters:
Name Type Description
width *

View Source client/ui/fields/field.js, line 562

this

# setValid()

Remove the invalid style

View Source client/ui/fields/field.js, line 648

this

# setValue(newValue, rawUpdateopt)

Set the field value

Parameters:
Name Type Attributes Description
newValue string | number | date

The new field value

rawUpdate boolean <optional>

If true, it doesn't update the associated record and doesn't trigger "change" event

View Source client/ui/fields/field.js, line 442

this

# setWidth(width)

Set the field width

Parameters:
Name Type Description
width *

View Source client/ui/fields/field.js, line 538

this

# validate() → {boolean}

Validate the field value and apply UI style accordingly

View Source client/ui/fields/field.js, line 424

true is the field is valid, false otherwise

boolean