Sha256: e72c6717cc2393bf866b1148ca1144b9d397a7738834ecbecbde113a559c8aad
Contents?: true
Size: 1.9 KB
Versions: 6
Compression:
Stored size: 1.9 KB
Contents
export function initForms() { console.log('\tForms'); var components = document.querySelectorAll('.v-form'); for (var i = 0; i < components.length; i++) { var component = components[i]; if (!component.vComponent) { component.vComponent = new VForm(component); } } } export class VForm { constructor(element) { this.element = element; } // Called whenever a form is about to be submitted. // returns true on success // returns on failure return an error object that can be processed by VErrors: // { email: ["email must be filled", "email must be from your domain"] } // { :page: ["must be filled"] } validate(form, params) { console.log("Form validate", form, params); var errors = []; for (let input of this.inputs()) { if (input.vComponent && input.vComponent.validate) { var result = input.vComponent.validate(form, params); if (result !== true) { errors.push(result); } } } return errors; } inputs() { return this.element.elements; } // Called to collect data for submission prepareSubmit(form, params) { for (let input of this.inputs()) { if (input.vComponent && input.vComponent.prepareSubmit) { input.vComponent.prepareSubmit(form, params); } } } initEventListener(eventName, eventHandler) { for (let input of this.inputs()) { if (input.vComponent && input.vComponent.initEventListener) { input.vComponent.initEventListener(eventName, eventHandler); } } } clear() { for (const input of this.inputs()) { if (input.vComponent && input.vComponent.clear) { input.vComponent.clear(); } } } }
Version data entries
6 entries across 6 versions & 1 rubygems