This mixin provides a common interface for the logical behavior and state of form fields, including:
*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.
The name of the field (defaults to undefined). By default this is used as the parameter name when including the field value in a form submit(). To prevent the field from being included in the form submit, set submitValue to false.
Specifies whether this field should be validated immediately whenever a change in its value is detected. Defaults to true. If the validation results in a change in the field's validity, a validitychange event will be fired. This allows the field to show feedback about the validity of its contents immediately as the user is typing.
When set to false, feedback will not be immediate. However the form will still be validated before submitting if the clientValidation option to Ext.form.Basic.doAction is enabled, or if the field or form are validated manually.
See also Ext.form.field.Base.checkChangeEventsfor controlling how changes to the field's value are detected.
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.
Flag denoting that this component is a Field. Always true.
Flag denoting that this component is a Field. Always true.
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.
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
.
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.
A function containing the transaction code
Checks whether the value of the field has changed since the last time it was checked. If the value has changed, it:
Checks the isDirty state of the field and if it has changed since the last time it was checked, fires the dirtychange event.
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.
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.
The value to get errors for (defaults to the current field value)
All error messages for this field; an empty Array if none.
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.
A mapping of submit parameter names to values; each value should be a string, or an array of strings if that particular name has multiple values. It can also return null if there are no parameters to be submitted.
Returns the name attribute of the field. This is used as the parameter name when including the field value in a form submit().
name The field name
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.
A mapping of submit parameter names to values; each value should be a string, or an array of strings if that particular name has multiple values. It can also return null if there are no parameters to be submitted.
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).
value The field value
Initializes this Field mixin on the current instance. Components using this mixin should call this method during their own initialization process.
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.
True if this field has been changed from its original value (and is not disabled), false otherwise.
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.
The first value to compare
The second value to compare
True if the values are equal, false if inequal.
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.
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.
True if the value is valid, else false
Resets the current field value to the originally loaded value and clears any validation messages. See Ext.form.Basic.trackResetOnLoad
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.
Sets a data value into the field and runs the change detection and validation.
Sets a data value into the field and runs the change detection and validation.
The value to set
this
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.
True if the value is valid, else false
Fires when a user-initiated change is detected in the value of the field.
Fires when a user-initiated change is detected in the value of the field.
The new value
The original value