Clear Up
SharpKit Reference

Field Interface

This mixin provides a common interface for the logical behavior and state of form fields, including:

  • Getter and setter methods for field values
  • Events and methods for tracking value and validity changes
  • Methods for triggering validation

NOTE: When implementing custom fields, it is most likely that you will want to extend the Ext.form.field.Base component class rather than using this mixin directly, as BaseField contains additional logic for generating an actual DOM complete with label and error message display and a form input field, plus methods that bind the Field value getters and setters to the input field's value.

If you do want to implement this mixin directly and don't want to extend Ext.form.field.Base, then you will most likely want to override the following methods with custom implementations: getValue, setValue, and getErrors. Other methods may be overridden as needed but their base implementations should be sufficient for common cases. You will also need to make sure that initField is called during the component's initialization.

Namespace: Ext.form.field

Methods

Name Description
batchChanges(Delegate) A utility for grouping a set of modifications which may trigger value changes into a single transaction, to prevent excessive firing of change events. This is useful for instance if the field has sub-fields which are being updated as a group; you don't want the container field to check its own changed state for each subfield change.
beforeReset() Template method before a field is reset.
checkChange() Checks whether the value of the field has changed since the last time it was checked. If the value has changed, it:
  • Fires the change event,
  • Performs validation if the validateOnChange config is enabled, firing the validitychange event if the validity has changed, and
  • Checks the dirty state of the field and fires the dirtychange event if it has changed.
  • checkDirty() Checks the isDirty state of the field and if it has changed since the last time it was checked, fires the dirtychange event.
    clearInvalid() Clear any invalid styles/messages for this field. Components using this mixin should implement this method to update the components rendering to clear any existing messages. Note: this method does not cause the Field's validate or isValid methods to return true if the value does not pass validation. So simply clearing a field's errors will not necessarily allow submission of forms submitted with the Ext.form.action.Submit.clientValidation option set.
    extractFileInput() Only relevant if the instance's isFileUpload method returns true. Returns a reference to the file input DOM element holding the user's selected file. The input will be appended into the submission form and will not be returned, so this method should also create a replacement.
    getErrors(object) Runs this field's validators and returns an array of error messages for any validation failures. This is called internally during validation and would not usually need to be used manually. Each subclass should override or augment the return value to provide their own errors.
    getModelData() Returns the value(s) that should be saved to the Ext.data.Model instance for this field, when Ext.form.Basic.updateRecord is called. Typically this will be an object with a single name-value pair, the name being this field's name and the value being its current data value. More advanced field implementations may return more than one name-value pair. The returned values will be saved to the corresponding field names in the Model. Note that the values returned from this method are not guaranteed to have been successfully validated.
    getName() Returns the name attribute of the field. This is used as the parameter name when including the field value in a form submit().
    getSubmitData() Returns the parameter(s) that would be included in a standard form submit for this field. Typically this will be an object with a single name-value pair, the name being this field's name and the value being its current stringified value. More advanced field implementations may return more than one name-value pair. Note that the values returned from this method are not guaranteed to have been successfully validated.
    getValue() Returns the current data value of the field. The type of value returned is particular to the type of the particular field (e.g. a Date object for Ext.form.field.Date).
    initField() Initializes this Field mixin on the current instance. Components using this mixin should call this method during their own initialization process.
    initValue() Initializes the field's value based on the initial config.
    isDirty() Returns true if the value of this Field has been changed from its originalValue. Will always return false if the field is disabled. Note that if the owning form was configured with trackResetOnLoad then the originalValue is updated when the values are loaded by Ext.form.Basic.setValues.
    isEqual(object, object) Returns whether two field values are logically equal. Field implementations may override this to provide custom comparison logic appropriate for the particular field's data type.
    isEqualAsString(object, object) Returns whether two values are logically equal. Similar to isEqual, however null or undefined values will be treated as empty strings.
    isFileUpload() Returns whether this Field is a file upload field; if it returns true, forms will use special techniques for submitting the form via AJAX. See Ext.form.Basic.hasUpload for details. If this returns true, the extractFileInput method must also be implemented to return the corresponding file input element.
    isValid() Returns whether or not the field value is currently valid by validating the field's current value. The validitychange event will not be fired; use validate instead if you want the event to fire. Note: disabled fields are always treated as valid. Implementations are encouraged to ensure that this method does not have side-effects such as triggering error message display.
    markInvalid(object) Associate one or more error messages with this field. Components using this mixin should implement this method to update the component's rendering to display the messages. Note: this method does not cause the Field's validate or isValid methods to return false if the value does pass validation. So simply marking a Field as invalid will not prevent submission of forms submitted with the Ext.form.action.Submit.clientValidation option set.
    onChange(object, object) Called when the field's value changes. Performs validation if the validateOnChange config is enabled, and invokes the dirty check.
    onDirtyChange(bool) Called when the field's dirty state changes.
    reset() Resets the current field value to the originally loaded value and clears any validation messages. See Ext.form.Basic.trackResetOnLoad
    resetOriginalValue() Resets the field's originalValue property so it matches the current value. This is called by Ext.form.Basic.setValues if the form's trackResetOnLoad property is set to true.
    setValue(object) Sets a data value into the field and runs the change detection and validation.
    transformOriginalValue(object) Allows for any necessary modifications before the original value is set
    validate() Returns whether or not the field value is currently valid by validating the field's current value, and fires the validitychange event if the field's validity has changed since the last validation. Note: disabled fields are always treated as valid. Custom implementations of this method are allowed to have side-effects such as triggering error message display. To validate without side-effects, use isValid.

    Properties

    Name Description
    className Defaults to: "Ext.Base"
    configMap Defaults to: {}
    initConfigList Defaults to: []
    initConfigMap Defaults to: {}
    isFormField Flag denoting that this component is a Field. Always true. Defaults to: true
    isInstance Defaults to: true
    originalValue The original value of the field as configured in the value configuration, or as loaded by the last form load operation if the form's trackResetOnLoad setting is true.
    self Get the reference to the current class from which this object was instantiated. Unlike statics, this.self is scope-dependent and it's meant to be used for dynamic inheritance. See statics for a detailed comparison
      Ext.define('My.Cat', {
                statics: {
                speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
                },
                constructor: function() {
                alert(this.self.speciesName); // dependent on 'this'
                },
                clone: function() {
                return new this.self();
                }
                });
                Ext.define('My.SnowLeopard', {
                extend: 'My.Cat',
                statics: {
                speciesName: 'Snow Leopard'         // My.SnowLeopard.speciesName = 'Snow Leopard'
                }
                });
                var cat = new My.Cat();                     // alerts 'Cat'
                var snowLeopard = new My.SnowLeopard();     // alerts 'Snow Leopard'
                var clone = snowLeopard.clone();
                alert(Ext.getClassName(clone));             // alerts 'My.SnowLeopard'
                
    suspendCheckChange Defaults to: 0
    © Copyright 2005-2011 SharpKit. All rights reserved.