Class

VPField

VPField()

VPField Instance

Constructor

# new VPField()

Field instances are responsible for managing the internal state of individual fields. Field instances are capable of formatting input and validating input based on various events. See examples for more information.

View Source Field.ts, line 71

Examples
// Simple DOM Binding, Field will be required
<div class="VPField">
  <input id="full-name" aria-label="Full Name" name="name" type="text" required="required" />
</div>
// Simple DOM Binding, pattern matching an email /.+@.+\..+/
<div class="VPField">
  <label for="email">Email Address</label>
  <input id="email" name="email" type="email" />
</div>
// Programmic bindings, phone number w/ input formatter
const field = new VP.Field(document.getElementById('phone'), {
   InputFormatter: {
     pre: (value) => value.replace(/[^0-9]/g, ''),
     post: (value) => {
       const areaCode = value.substr(0, 3)
       const local = value.substr(3, 3)
       const number = value.substr(6, 4)

       let mask = '('
       if (areaCode.length > 0) mask += areaCode
       if (local.length > 0) mask += ') ' + local
       if (number.length > 0) mask += '-' + number
       return mask
     }
   }
});

Extends

Classes

VPField

Methods

# addEventListener(event_name, callback)

Add an event listener

Parameters:
Name Type Description
event_name string

Name of the event

callback EventCallback

Event callback to fire

Overrides:

View Source mixins/EventEmitter.ts, line 22

# addMessage(message, statusopt)

Adds a unique message to the $MessageNode

Parameters:
Name Type Attributes Description
message

The message to append

status <optional>

An optional class to append indicating message status

Overrides:

View Source lib/DOMMessaging.ts, line 104

If the $MessageNode isn't set or isn't an HTMLElement

# addMessages(messages, statusopt)

Batch append messages

Parameters:
Name Type Attributes Description
messages

The messages to append

status <optional>

An optional class to append indicating message status

Overrides:

View Source lib/DOMMessaging.ts, line 125

If the $MessageNode isn't set or isn't an HTMLElement

# clearMessages()

Clear all messages from the $MessageNode (If set)

Overrides:

View Source lib/DOMMessaging.ts, line 146

# createEvent(event_name, options) → {Event}

Helper for creating a new event, supporting IE9

Parameters:
Name Type Description
event_name string

Name of the event

options EventOptions

Event options

Overrides:

View Source mixins/EventEmitter.ts, line 70

Event

# dispatchEvent(event, data) → {boolean}

Include support for passing data along event

Parameters:
Name Type Description
event Event

the Event object to dispatch

data any

Data to be passed to the callback

Overrides:

View Source mixins/EventEmitter.ts, line 52

boolean

# generateMessageNode(anchoropt, posopt)

Generate a messageNode where messages can be added and removed in a managed way.

Parameters:
Name Type Attributes Description
anchor <optional>

The anchor to use for the $MessageNode (Defaults to $MessageAnchor)

pos <optional>

The position to set $MessageNode inside the $MessageAnchor

Overrides:

View Source lib/DOMMessaging.ts, line 68

If anchor isn't an Element

If pos isn't a valid

VerticalPosition

# isElementVisible(element)

Helper method to determine if the element is visible within the DOM

Parameters:
Name Type Description
element HTMLElement

Element to test

Overrides:

View Source Validatable.ts, line 149

boolean

# isValid()

Standard Validation cycle for the Field instance.

  • Validation can occur as either synchronous validation or asynchronous validation.
  • Validation emulates standard DOM validation
  • Validation consumes custom validation rules
    • If Validation rules are all synchronous, isValid will be synchronous
    • If Validation rules are async, isValid will be asynchronous
    • If ValidateAsync option is enabled, isValid will ALWAYS be asynchronous

This method applies the necessary formatting for input values, if defined.

View Source Field.ts, line 291

(boolean|Promise.)

# parseInput()

Parses the internally tracked input and returns a standard interface used internally for the validation cycle.

View Source Field.ts, line 241

# remove()

Notify parent that this field should be removed from tracking. This is handled automatically if using a modern browser where MutationObservers are support (IE11+). For most use-cases, this can be safely ignored; This method is provided for very specific edge cases where the internally tracked input may be removed after initialization.

View Source Field.ts, line 232

# removeEventListener(event_name, callback) → {EventCallback|null}

Remove an event listener

Parameters:
Name Type Description
event_name string

Name of the event

callback EventCallback

The event callback to remove

Overrides:

View Source mixins/EventEmitter.ts, line 34

EventCallback | null

# removeMessage(message)

Remove a message

Parameters:
Name Type Description
message

The message to remove

Overrides:

View Source lib/DOMMessaging.ts, line 135

If the $MessageNode isn't set or isn't an HTMLElement

# removeMessageNode()

Removes the $MessageNode from the $MessageAnchor

Overrides:

View Source lib/DOMMessaging.ts, line 92

If the $MessageNode isn't set or isn't an HTMLElement

# scrollTo()

Scroll to the tracked element

Overrides:

View Source Validatable.ts, line 86