Easily create forms with automatic insert and update, and automatic reactive validation.
API documentation automatically generated by docmeteor.
This property Utility is defined in AutoForm
AutoForm.Utility = Utility;
autoform-api.js:11
This method addHooks is defined in AutoForm
Arguments
- formIds {String[]|String|null}
Form id
or array of form IDs to which these hooks apply. Specify null
to add hooks that will run for every form.
- hooks {Object}
Hooks to add, where supported names are "before", "after", "formToDoc", "docToForm", "onSubmit", "onSuccess", and "onError".
Returns {undefined}
Defines hooks to be used by one or more forms. Extends hooks lists if called multiple times for the same form.
AutoForm.addHooks = function autoFormAddHooks(formIds, hooks, replace) { ...
autoform-api.js:23
This method hooks is defined in AutoForm
Arguments
- hooks {Object}
Returns {undefined}
Defines hooks by form id. Extends hooks lists if called multiple times for the same form.
AutoForm.hooks = function autoFormHooks(hooks, replace) { ...
autoform-api.js:51
This property _hooks is defined in AutoForm
Hooks list to aid automated testing
AutoForm._hooks = Hooks.form;
autoform-api.js:63
This property _globalHooks is defined in AutoForm
Global hooks list to aid automated testing
AutoForm._globalHooks = Hooks.global;
autoform-api.js:71
This method _forceResetFormValues is defined in AutoForm
Arguments
- formId {String}
Returns {undefined}
Forces an AutoForm's values to properly update. See https:
AutoForm._forceResetFormValues = function autoFormForceResetFormValues(formId) { ...
autoform-api.js:82
This method resetForm is defined in AutoForm
Arguments
- formId {String}
- template {TemplateInstance} (Optional)
Looked up if not provided. Pass in for efficiency.
Returns {undefined}
Resets an autoform, including resetting validation errors. The same as clicking the reset button for an autoform.
AutoForm.resetForm = function autoFormResetForm(formId, template) { ...
autoform-api.js:100
This method setDefaultTemplate is defined in AutoForm
Arguments
- template {String}
AutoForm.setDefaultTemplate = function autoFormSetDefaultTemplate(template) { ...
autoform-api.js:111
This method getDefaultTemplate is defined in AutoForm
Reactive.
AutoForm.getDefaultTemplate = function autoFormGetDefaultTemplate() { ...
autoform-api.js:122
This method setDefaultTemplateForType is defined in AutoForm
Arguments
- type {String}
- template {String}
AutoForm.setDefaultTemplateForType = function autoFormSetDefaultTemplateForType(type, template) { ...
autoform-api.js:133
This method getDefaultTemplateForType is defined in AutoForm
Arguments
- type {String}
Returns {String} Template name
Reactive.
AutoForm.getDefaultTemplateForType = function autoFormGetDefaultTemplateForType(type) { ...
autoform-api.js:152
This method getTemplateName is defined in AutoForm
Arguments
- templateType {String}
- templateName {String}
- fieldName {String} (Optional)
- skipExistsCheck {Boolean} (Optional)
Pass true
to return a template name even if that template hasn't been defined.
Returns {String} Template name
Returns the full template name. In the simplest scenario, this is templateType_templateName as passed in. However, if templateName is not provided, it is looked up in the following manner:
- autoform..template from the schema (field+type override for all forms)
- autoform.template from the schema (field override for all forms)
- template- attribute on an ancestor component within the same form (form+type for all fields)
- template attribute on an ancestor component within the same form (form specificity for all types and fields)
- Default template for component type, as set by AutoForm.setDefaultTemplateForType
- Default template, as set by AutoForm.setDefaultTemplate.
- Built-in default template, currently bootstrap-3.
AutoForm.getTemplateName = function autoFormGetTemplateName(templateType, templateName, fieldName, skipExistsCheck) { ...
autoform-api.js:181
This method getFormValues is defined in AutoForm
Arguments
- formId {String}
The id
attribute of the autoForm
you want current values for.
- template {Template} (Optional)
The template instance, if already known, as a performance optimization.
- ss {SimpleSchema} (Optional)
The SimpleSchema instance, if already known, as a performance optimization.
- getModifier {Boolean} (Optional)
Set to true
to return a modifier object or false
to return a normal object. For backwards compatibility, and object containing both is returned if this is undefined.
Returns {Object|null}
Returns an object representing the current values of all schema-based fields in the form.
The returned object is either a normal object or a MongoDB modifier, based on the getModifier
argument. Return value may be null
if the form is not currently rendered on screen.
AutoForm.getFormValues = function autoFormGetFormValues(formId, template, ss, getModifier) { ...
autoform-api.js:255
This method getFieldValue is defined in AutoForm
Arguments
- fieldName {String}
The name of the field for which you want the current value.
- formId {String} (Optional)
The id
attribute of the autoForm
you want current values for. Default is the closest form from the current context.
Returns {Any|undefined}
Returns the value of the field (the value that would be used if the form were submitted right now). This is a reactive method that will rerun whenever the current value of the requested field changes. Return value will be undefined if the field is not currently rendered.
AutoForm.getFieldValue = function autoFormGetFieldValue(fieldName, formId) { ...
autoform-api.js:409
This method getInputTypeTemplateNameForElement is defined in AutoForm
Arguments
- element {DOMElement}
The input DOM element, generated by an autoform input control
Returns {String}
Returns the name of the template used to render the element.
AutoForm.getInputTypeTemplateNameForElement = function autoFormGetInputTypeTemplateNameForElement(element) { ...
autoform-api.js:444
This method getInputValue is defined in AutoForm
Arguments
- element {DOMElement}
The input DOM element, generated by an autoform input control, which must have a data-schema-key
attribute set to the correct schema key name.
- ss {SimpleSchema} (Optional)
Provide the SimpleSchema instance if you already have it.
Returns {Any}
Returns the value of the field (the value that would be used if the form were submitted right now).
Unlike AutoForm.getFieldValue
, this function is not reactive.
AutoForm.getInputValue = function autoFormGetInputValue(element, ss) { ...
autoform-api.js:472
This method addInputType is defined in AutoForm
Arguments
- name {String}
The type string that this definition is for.
- definition {Object}
Defines how the input type should be rendered.
* __componentName__ *{String}*
The component name. A template with the name <componentName>_bootstrap3, and potentially others, must be defined.
Returns {undefined}
Use this method to add custom input components.
AutoForm.addInputType = function afAddInputType(name, definition) { ...
autoform-api.js:565
This method addFormType is defined in AutoForm
Arguments
- name {String}
The type string that this definition is for.
- definition {Object}
Defines how the submit type should work
* __adjustInputContext__ *{Function}* (Optional)
A function that accepts a single argument, which is the context with which an input template in the form will be called, potentially changes the context object, and then returns it. For example, the "readonly" and "disabled" form types use this function to add the "readonly" or "disabled" attribute, respectively, to every input within the form.
* __adjustSchema__ *{Function}* (Optional)
A function that accepts a single argument, which is the form schema, and potentially uses that to return a different schema to use instead. For example, the "update-pushArray" form type uses this function to build and return a schema that is limited by the `scope` attribute on the form. When this function is called, `this` contains useful information about the form.
* __hideArrayItemButtons__ *{Boolean}* (Optional)
Set to `true` if this form type should not show buttons for adding and removing items in an array field. The "disabled" and "readonly" form types do this.
* __onSubmit__ *{Function}*
A function that does whatever should happen upon submission of this form type. When this function is called, `this` contains useful information about the form. At a minimum, you probably want to call `this.event.preventDefault()` to prevent the browser from submitting the form. Your submission logic may want to rely on additional custom form attributes, which will be available in `this.formAttributes`. If you do any additional validation and it fails, you should call `this.failedValidation()`. When your logic is done, you should call `this.result(error, result)`. If you want to end the submission process without providing a result, call `this.endSubmission()`. If you don't call `this.result()` or `this.endSubmission()`, `endSubmit` hooks won't be called, so for example the submit button might remain disabled. `onError` hooks will be called only if you pass an error to `this.result()`. `onSuccess` hooks will be called only if you do not pass an error to `this.result()`.
* __shouldPrevalidate__ *{Function}* (Optional)
A function that returns `true` if validation against the form schema should happen before the `onSubmit` function is called, or `false` if not. When this function is called, `this` contains useful information about the form. If this function is not provided for a form type, the default is `true`.
* __validateForm__ *{Function}*
A function that validates the form and returns `true` if valid or `false` if not. This can happen during submission but also at other times. When this function is called, `this` contains useful information about the form and the validation options.
Returns {undefined}
Use this method to add custom form types.
AutoForm.addFormType = function afAddFormType(name, definition) { ...
autoform-api.js:586
This method validateField is defined in AutoForm
Arguments
- formId {String}
The id
attribute of the autoForm
you want to validate.
- fieldName {String}
The name of the field within the autoForm
you want to validate.
- skipEmpty {Boolean} (Optional, Default = false)
Set to true
to skip validation if the field has no value. Useful for preventing required
errors in form fields that the user has not yet filled out.
Returns {Boolean} Is it valid?
In addition to returning a boolean that indicates whether the field is currently valid, this method causes the reactive validation messages to appear.
AutoForm.validateField = function autoFormValidateField(formId, fieldName, skipEmpty) { ...
autoform-api.js:603
This method validateForm is defined in AutoForm
Arguments
- formId {String}
The id
attribute of the autoForm
you want to validate.
Returns {Boolean} Is it valid?
In addition to returning a boolean that indicates whether the form is currently valid, this method causes the reactive validation messages to appear.
AutoForm.validateForm = function autoFormValidateForm(formId) { ...
autoform-api.js:616
This method getValidationContext is defined in AutoForm
Arguments
- formId {String}
The id
attribute of the autoForm
for which you want the validation context
Returns {SimpleSchemaValidationContext} The SimpleSchema validation context object.
Use this method to get the validation context, which can be used to check the current invalid fields, manually invalidate fields, etc.
AutoForm.getValidationContext = function autoFormGetValidationContext(formId) { ...
autoform-api.js:652
This method findAttribute is defined in AutoForm
Arguments
- attrName {String}
Attribute name
Returns {Any|undefined} Searches for the given attribute, looking up the parent context tree until the closest autoform is reached.
Call this method from a UI helper. Might return undefined.
AutoForm.findAttribute = function autoFormFindAttribute(attrName) { ...
autoform-api.js:665
This method findAttributesWithPrefix is defined in AutoForm
Arguments
- prefix {String}
Attribute prefix
Returns {Object} An object containing all of the found attributes and their values, with the prefix removed from the keys.
Call this method from a UI helper. Searches for attributes that start with the given prefix, looking up the parent context tree until the closest autoform is reached.
AutoForm.findAttributesWithPrefix = function autoFormFindAttributesWithPrefix(prefix) { ...
autoform-api.js:706
This method debug is defined in AutoForm
Call this method in client code while developing to turn on extra logging. You need to call it just one time, usually in top level client code.
AutoForm.debug = function autoFormDebug() { ...
autoform-api.js:750
This property arrayTracker is defined in AutoForm
AutoForm.arrayTracker = arrayTracker;
autoform-api.js:764
This method getInputType is defined in AutoForm
Arguments
- atts {Object}
The attributes provided to afFieldInput.
Returns {String}
The input type. Most are the same as the type
attributes for HTML input elements, but some are special strings that autoform interprets.
Call this method from a UI helper to get the type string for the input control.
AutoForm.getInputType = function getInputType(atts) { ...
autoform-api.js:774
This method getSchemaForField is defined in AutoForm
Arguments
- name {String}
The field name attribute / schema key.
Returns {Object|undefined}
Call this method from a UI helper to get the field definitions based on the schema used by the closest containing autoForm.
AutoForm.getSchemaForField = function autoFormGetSchemaForField(name) { ...
autoform-api.js:863
This method _getOptionsForField is defined in AutoForm
Arguments
- name {String}
The field name attribute / schema key.
Returns {Array(Object)|String|undefined}
Call this method from a UI helper to get the select options for the field. Might return the string "allowed".
AutoForm._getOptionsForField = function autoFormGetOptionsForField(name) { ...
autoform-api.js:877
This method getLabelForField is defined in AutoForm
Arguments
- name {String}
The field name attribute / schema key.
Returns {Object}
Call this method from a UI helper to get the field definitions based on the schema used by the closest containing autoForm.
AutoForm.getLabelForField = function autoFormGetLabelForField(name) { ...
autoform-api.js:911
This method templateInstanceForForm is defined in AutoForm
Arguments
- formId {String} (Optional)
The form's id
attribute
Returns {TemplateInstance|undefined} The template instance.
Gets the template instance for the form with formId or the closest form to the current context.
AutoForm.templateInstanceForForm = function (formId) { ...
autoform-api.js:930
This method viewForForm is defined in AutoForm
Arguments
- formId {String} (Optional)
The form's id
attribute. Do not pass this if calling from within a form context.
Returns {Blaze.View|undefined}
The Blaze.View
instance for the autoForm.
Gets the Blaze.View
instance for the form with formId or the closest form to the current context.
AutoForm.viewForForm = function (formId) { ...
autoform-api.js:946
This method getArrayCountFromDocForField is defined in AutoForm
Arguments
- formId {String}
The form's id
attribute
- field {String}
The field name (schema key)
Returns {Number|undefined} Array count in the attached document.
Looks in the document attached to the form to see if the requested field exists and is an array. If so, returns the length (count) of the array. Otherwise returns undefined.
AutoForm.getArrayCountFromDocForField = function (formId, field) { ...
autoform-api.js:983
This method parseData is defined in AutoForm
Arguments
- data {Object}
Current data context for the form, or an empty object. Usually this is used from a quickForm, since the autoForm won't be rendered yet. Otherwise you should use AutoForm.getCurrentDataForForm if you can.
Returns {Object} Current data context for the form, or an empty object.
Parses and alters the current data context for a form. It will have default values added and a _resolvedSchema
property that has the schema the form should use.
AutoForm.parseData = function (data) { ...
autoform-api.js:1003
This method getCurrentDataForForm is defined in AutoForm
Arguments
- formId {String}
The form's id
attribute
Returns {Object} Current data context for the form, or an empty object.
Returns the current data context for a form. You can call this without a formId from within a helper and the data for the nearest containing form will be returned.
AutoForm.getCurrentDataForForm = function (formId) { ...
autoform-api.js:1017
This method getCurrentDataPlusExtrasForForm is defined in AutoForm
Arguments
- ____ {any}
{String} [formId] The form's id
attribute
Returns {Object} Current data context for the form, or an empty object.
Returns the current data context for a form plus some extra properties. You can call this without a formId from within a helper and the data for the nearest containing form will be returned.
AutoForm.getCurrentDataPlusExtrasForForm = function (formId) { ...
autoform-api.js:1039
This method getFormCollection is defined in AutoForm
Arguments
- formId {String}
The form's id
attribute
Returns {Mongo.Collection|undefined} The Collection instance
Gets the collection for a form from the collection
attribute
AutoForm.getFormCollection = function (formId) { ...
autoform-api.js:1059
This method getFormSchema is defined in AutoForm
Arguments
- formId {String}
The form's id
attribute
- form {Object} (Optional)
Pass the form data context as an optimization or if the form is not yet rendered.
Returns {SimpleSchema|undefined} The SimpleSchema instance
Gets the schema for a form, from the schema
attribute if
provided, or from the schema attached to the Mongo.Collection
specified in the collection
attribute. The form must be
currently rendered.
AutoForm.getFormSchema = function (formId, form) { ...
autoform-api.js:1076
This method getFormId is defined in AutoForm
Returns {String}
The containing form's id
attribute value
Call in a helper to get the containing form's id
attribute. Reactive.
AutoForm.getFormId = function () { ...
autoform-api.js:1088
This method selectFirstInvalidField is defined in AutoForm
Arguments
- formId {String}
The id
attribute of the form
- ss {SimpleSchema}
The SimpleSchema instance that was used to create the form's validation context.
Returns {undefined}
Selects the focus the first field (in DOM order) with an error.
AutoForm.selectFirstInvalidField = function selectFirstInvalidField(formId, ss) { ...
autoform-api.js:1101
This method _validateFormDoc is defined in AutoForm
Arguments
- doc {Object}
The document with the gathered form values to validate.
- isModifier {Boolean}
Is doc
actually a mongo modifier object?
- formId {String}
The form id
attribute
- ss {SimpleSchema}
The SimpleSchema instance against which to validate.
- form {Object}
The form context object
- key {String} (Optional)
Optionally, a specific schema key to validate.
Returns {Boolean} Is the form valid?
If creating a form type, you will often want to call this from the validateForm
function. It provides the generic form validation logic that does not typically change between form types.
AutoForm._validateFormDoc = function validateFormDoc(doc, isModifier, formId, ss, form, key) { ...
autoform-api.js:1155
This method stringToNumber is defined in AutoForm.valueConverters
Arguments
- val {String}
A string or null or undefined.
Returns {Number|String} The string converted to a Number or the original value.
For strings, returns Number(val) unless the result is NaN. Otherwise returns val.
stringToNumber: function stringToNumber(val) { ...
inputTypes/value-converters.js:141