///
This is the facade that sits between individual inputs/fields and the Forms JS {@link Form}. * It handles validation (using {@link ValidationService}) and caches the result for easy access by the view layer. */ class AttributeMetadata { private disabled_; private errorMessages_; private fieldName_; private form_; private pristine_; private uuid_; /** * Constructor. * * @param form Forms JS form * @param fieldName Attribute key within form data object */ constructor(form: Form, fieldName: string); /** * This field's view (input) should be disabled. * *
This value may indicate that the form is currently being submitted.
*/
disabled: boolean;
/**
* Error messages for this field as of the time it was last validated.
*/
errorMessages: Array This method will also update the cached validation state once validation has completed.
*
* @return Promise to be resolved or rejected upon validation completion.
*/
validate(): Promise Despite its name, this is not an HTMLFormElement nor does it directly interact with one.
* This object is responsible for tracking fields/inputs and ensuring their validity before allowing a submit action.
*/
class Form {
private disabled_;
private fieldNameToAttributeMetadata_;
private formData_;
private strings_;
private validationSchema_;
private validationService_;
/**
* Constructor.
*/
constructor();
/**
* This form (and all child input elements) is disabled.
*/
disabled: boolean;
/**
* The POJO being edited by this form.
*/
formData: any;
/**
* Set the strings for this specific form.
* See {@link Strings}.
*/
strings: Strings;
/**
* This form's validations schema.
*/
validationSchema: ValidationSchema;
/**
* Returns a ValidationService configured for the current Form.
*/
validationService: ValidationService;
/**
* Register a field with the form.
*
* All registered form-fields must be valid before the form will enable submission.
*/
registerAttribute(fieldName: string): AttributeMetadata;
/**
* Unregister a form field.
*/
unregisterAttribute(fieldName: string): void;
/**
* Validate all registered form-fields in preparation for submission.
*
* This method returns a Promise that will resolve if all fields are found valid or reject if any field isn't.
* This validation process will also update all {@link AttributeMetadata}s.
* This in turn may cause view/binding updates.
*/
validate(): Promise Enum validations will fail with a default error message unless overridden with "enumFailureMessage".
*/
enumeration?: Array Use a The attribute type will determine which type of comparison this constraint results in:
* Max validations will fail with a default error message unless overridden with "maxFailureMessage".
*/
max?: number;
/**
* Optional custom failure message used in the event of a failed "max" validation.
*
* Use a The attribute type will determine which type of comparison this constraint results in:
* Min validations will fail with a default error message unless overridden with "minFailureMessage".
*/
min?: number;
/**
* Optional custom failure message used in the event of a failed "min" validation.
*
* Use a Pattern validations will fail with a default error message unless overridden with "patternFailureMessage".
*/
pattern?: RegExp;
/**
* Optional custom failure message used in the event of a failed "pattern" validation.
*
* Use a Required validations will fail with a default error message unless overridden with "requiredFailureMessage".
*/
required?: boolean;
/**
* Optional custom failure message used in the event of a failed "required" validation.
*/
requiredFailureMessage: string;
/**
* Optional primitive attribute type.
*
* If no value is specified this field will be treated as type "string".
* Additional supported types include: "boolean", "integer", and "float".
*
* Type validations will fail with a default error message unless overridden with "typeFailureMessage".
*/
type?: ValidationType;
/**
* Optional custom failure message used in the event of a failed "type" validation.
*
* Use a Validations functions are provided two parameters:
* Custom validators are responsible for returning either a truthy/falsy value OR a Promise.
* Synchronous validations can return TRUE to indicate a valid value or FALSE to indicate an invalid value.
* Use a Promise to perform asynchronous validation or to return a custom failure message.
*/
interface ValidatorFunction {
(value: any, formData: any): boolean | Promise For example, Arrays can also be flattened.
* Their flattened keys will take the form of 'myArray[0]' and 'myArray[0].myNestedProperty'.
*/
static flatten(object: any): Array For example, the key 'foo.bar' would return "baz" for the object For example, writing "baz" to the key 'foo.bar' would result in an object
*
*/
class Strings {
static booleanTypeValidationFailed: string;
static customValidationFailed: string;
static enumerationValidationFailed: string;
static floatTypeValidationFailed: string;
static integerTypeValidationFailed: string;
static maximumNumberValidationFailed: string;
static maxStringLengthValidationFailed: string;
static minimumNumberValidationFailed: string;
static minStringLengthValidationFailed: string;
static patternValidationFailed: string;
static requiredValidationFailed: string;
static stringTypeValidationFailed: string;
private booleanTypeValidationFailed_;
private customValidationFailed_;
private enumerationValidationFailed_;
private floatTypeValidationFailed_;
private integerTypeValidationFailed_;
private maximumNumberValidationFailed_;
private maxStringLengthValidationFailed_;
private minimumNumberValidationFailed_;
private minStringLengthValidationFailed_;
private patternValidationFailed_;
private requiredValidationFailed_;
private stringTypeValidationFailed_;
constructor();
booleanTypeValidationFailed: string;
customValidationFailed: string;
enumerationValidationFailed: string;
floatTypeValidationFailed: string;
integerTypeValidationFailed: string;
maximumNumberValidationFailed: string;
maxStringLengthValidationFailed: string;
minimumNumberValidationFailed: string;
minStringLengthValidationFailed: string;
patternValidationFailed: string;
requiredValidationFailed: string;
stringTypeValidationFailed: string;
}
}
declare module formsjs {
/**
* Supported type validations.
*/
enum ValidationType {
BOOLEAN,
FLOAT,
INTEGER,
STRING,
}
}
declare module formsjs {
/**
* The set of supported validation constraints that can be specified for an attribute.
*/
interface ValidatableAttribute {
/**
* Attribute name within form data object (e.g. "username" within {username: "John Doe"}).
* This is a convenience attribute added by Forms JS based on the map key in {@link ValidationSchema}.
* @private
*/
key_: string;
/**
* Optional set of acceptable values; any attributes values not within this set will be considered invalid.
*
* ${value} token to include the attribute's current string value,
* (e.g. if value is "foobar" then "${value} is not allowed" becomes "foobar is not allowed").
*/
enumerationFailureMessage?: string;
/**
* Maximum length/size of attribute.
*
*
*
*
* ${value} token to include the attribute's current numeric value,
* (e.g. if value is 1.0 then "${value} is not allowed" becomes "1.0 is not allowed").
*/
maxFailureMessage?: string;
/**
* Minimum length/size of attribute.
*
*
*
*
* ${value} token to include the attribute's current numeric value,
* (e.g. if value is 1.0 then "${value} is not allowed" becomes "1.0 is not allowed").
*/
minFailureMessage?: string;
/**
* Regular expression pattern that string values must match.
*
* ${value} token to include the attribute's current string value,
* (e.g. if value is "foobar" then "${value} is not allowed" becomes "foobar is not allowed").
*/
patternFailureMessage: string;
/**
* This attribute is required.
*
* ${value} token to include the attribute's current string value,
* (e.g. if value is "foobar" then "${value} is not an allowed type" becomes "foobar is not an allowed type").
*/
typeFailureMessage: string;
/**
* Set of custom validator functions; see {@link ValidatorFunction}.
*/
validators?: Array
*
*
* {foo: {bar: 'baz'}} will become flattened into '['foo', 'foo.bar'].
*
* {foo: {bar: "baz"}}.
* The key 'foo[1].baz' would return 2 for the object {foo: [{bar: 1}, {baz: 2}]}.
*/
static read(flattenedKey: string, object: any): any;
/**
* Writes a value to the location specified by a flattened key and creates nested structure along the way as needed.
*
* {foo: {bar: "baz"}}.
* Writing 3 to the key 'foo[0].bar' would result in an object {foo: [{bar: 3}]}.
*/
static write(value: any, flattenedKey: string, object: any): void;
/**
* Helper method for initializing a missing property.
*
* @throws Error if unrecognized property specified
* @throws Error if property already exists of an incorrect type
*/
private static createPropertyIfMissing_(key, object, propertyType);
}
}
declare module formsjs {
/**
* UID generator for formFor input fields.
* @see http://stackoverflow.com/questions/6248666/how-to-generate-short-uid-like-ax4j9z-in-js
*/
class UID {
/**
* Create a new UID.
*/
static create(): string;
}
}
declare module formsjs {
class ValidationPromiseBuilder {
private failureMessages_;
private promise_;
private promiseRejecter_;
private promiseResolver_;
private promises_;
constructor(promises?: Array