From 291d2c3bba1e2ebb55d8943e08d28b3957d2f0e5 Mon Sep 17 00:00:00 2001 From: SrijanSao Date: Wed, 6 Nov 2024 07:41:54 +0000 Subject: [PATCH 1/9] Form list Validation changes --- lib/components/FormList.js | 141 ++++++++++++++++++++++++++++++++----- lib/forms/Form.js | 48 ++++++++++--- 2 files changed, 163 insertions(+), 26 deletions(-) diff --git a/lib/components/FormList.js b/lib/components/FormList.js index 47ae2d3..929edc0 100644 --- a/lib/components/FormList.js +++ b/lib/components/FormList.js @@ -1,5 +1,5 @@ 'use strict'; - +const async = require('async') const FORMLIST_CHANGE_MESSAGE = 'mlformlistchange'; const MLFormList = module.exports = milo.createComponentClass({ @@ -15,7 +15,7 @@ const MLFormList = module.exports = milo.createComponentClass({ }, model: undefined, dom: { - cls: [ 'form-list', 'ml-ui-form-list' ] + cls: ['form-list', 'ml-ui-form-list'] }, events: { messages: { @@ -27,11 +27,13 @@ const MLFormList = module.exports = milo.createComponentClass({ init: MLFormList$init, moveItem: MLFormList$moveItem, setItemSchema: MLFormList$setItemSchema, - destroy: MLFormList$destroy + destroy: MLFormList$destroy, + validateModel: MLFormList$validateModel, + clearSubSchemaValidation: MLFormList$clearSubSchemaValidation } }); -function handleClick (type, event) { +function handleClick(type, event) { const component = milo.Component.getContainingComponent(event.target); if (component && component.name) { const formList = component.getScopeParentWithClass('MLFormList'); @@ -49,12 +51,14 @@ function handleClick (type, event) { } } -function MLFormList$init () { +function MLFormList$init() { MLFormList.super.init.apply(this, arguments); this.once('childrenbound', onChildrenBound); + // _manageFormValidation.call(this); + this._invalidFormControls = {} } -function MLFormList$setItemSchema (schema) { +function MLFormList$setItemSchema(schema) { this._subFormSchema = schema.subSchema; this._movable = !!schema.allowMove; this._deletable = !!schema.allowDelete; @@ -63,18 +67,18 @@ function MLFormList$setItemSchema (schema) { showHidePrepend.call(this); } -function MLFormList$moveItem (fromIndex, toIndex) { +function MLFormList$moveItem(fromIndex, toIndex) { const toInsert = this.model.m.splice(fromIndex, 1); if (toInsert) return this.model.m.splice(toIndex, 0, toInsert[0]); } -function MLFormList$destroy () { +function MLFormList$destroy() { if (this._connector) milo.minder.destroyConnector(this._connector); this._connector = null; MLFormList.super.destroy.apply(this, arguments); } -function onChildrenBound () { +function onChildrenBound() { const scope = this.container.scope; this._connector = milo.minder(this.model, '->>>', scope.list.data).deferChangeMode('<<<->>>'); scope.addBtn && scope.addBtn.events.on('click', { subscriber: addItem, context: this }); @@ -92,37 +96,140 @@ function showHidePrepend() { scope.addBtnBefore.el.classList.toggle('hidden', !this._prepend || !model || model.length === 0); } -function addItem () { +function addItem() { this.model.m.push({}); } -function addItemBefore () { +function addItemBefore() { this.model.m.unshift({}); } -function MLFormList_get () { +function MLFormList_get() { const model = this.model.get(); return model ? _.clone(model) : undefined; } -function MLFormList_set (value) { +function MLFormList_set(value) { this.model.set(value); _triggerExternalPropagation.call(this); } -function MLFormList_del () { +function MLFormList_del() { const res = this.model.set([]); _triggerExternalPropagation.call(this); return res; } -function MLFormList_splice (index, howmany) { - const args = [ index, howmany ].concat(Array.prototype.slice.call(arguments, 2)); +function MLFormList_splice(index, howmany) { + const args = [index, howmany].concat(Array.prototype.slice.call(arguments, 2)); this.model.splice.apply(this.model, args); _triggerExternalPropagation.call(this); } -function _triggerExternalPropagation () { +function _triggerExternalPropagation() { this.data.dispatchSourceMessage(FORMLIST_CHANGE_MESSAGE); showHidePrepend.call(this); } + +function MLFormList$clearSubSchemaValidation() { + this._invalidFormControls = {}; +} + +function MLFormList$validateModel(callback, invalidControls) { + var validations = [] + , self = this; + this._dataValidations = { fromModel: {} }; + this.model.m().get().forEach((data, index) => { + this._subFormSchema.items.forEach((item) => { + if (item.validate && item.validate.fromModel && item.validate.fromModel[0] === 'required') { + this._dataValidations.fromModel[`${index}${item.modelPath}`] = [validateRequired]; + } + }) + }) + + + _.eachKey(this._dataValidations.fromModel, function (validators, modelPath) { + const [index, path] = modelPath.split('.'); + var data = this.model.m().get()[index][path]; + validators = Array.isArray(validators) ? validators : [validators]; + + if (validators && validators.length) { + validations.push({ + modelPath: modelPath, + data: data, + validators: validators + }); + } + }, this); + + + var allValid = true; + async.each(validations, + function (validation, nextValidation) { + var lastResponse; + async.every(validation.validators, + // call validator + function (validator, next) { + validator(validation.data, function (err, response) { + lastResponse = response || {}; + next(err, lastResponse.valid); + }); + }, + // post validation result of item to form + function (err, valid) { + lastResponse.path = validation.modelPath; + lastResponse.valid = valid; + createOnValidatedd.call(self, lastResponse, invalidControls); + if (!valid) allValid = false; + nextValidation(null); + } + ); + }, + function (err) { + invalidControls = {...invalidControls, ...self._invalidFormControls}; + callback && callback({allValid, invalidControls}); + } + ); +} + +/** + * Validation functions + */ +function validateRequired(data, callback) { + var valid = typeof data != 'undefined' + && (typeof data != 'string' || data.trim() != ''); + var response = MLForm$$validatorResponse(valid, 'please enter a value', 'REQUIRED'); + callback(null, response); +} + + +function MLForm$$validatorResponse(valid, reason, reasonCode) { + return valid + ? { valid: true } + : { valid: false, reason: reason, reasonCode: reasonCode }; +} + +function createOnValidatedd(response) { + var reason; + if (response.valid) + delete this._invalidFormControls[response.path]; + else { + reason = { + label: `List Item ${response.path}`, + reason: response.reason, + reasonCode: response.reasonCode + }; + this._invalidFormControls[response.path] = { + reason: reason + }; + } + + var data = _.clone(response); + + if (reason) { + data.reason = reason; + delete data.reasonCode; + } + +} + diff --git a/lib/forms/Form.js b/lib/forms/Form.js index 3be91b3..28b6f7b 100644 --- a/lib/forms/Form.js +++ b/lib/forms/Form.js @@ -138,6 +138,7 @@ _.extendProto(MLForm, { viewPathSchema: MLForm$viewPathSchema, getModelPath: MLForm$getModelPath, getViewPath: MLForm$getViewPath, + getSubSchemas: MLForm$getSubSchemas, destroy: MLForm$destroy, }); @@ -542,6 +543,25 @@ function MLForm$viewPathComponent(viewPath) { return viewPathObj && viewPathObj.component; } +/** + * Returns component for a given view path (path as defined in Data facet) + * + * @param {String} viewPath + * @return {Component} + */ +function MLForm$getSubSchemas() { + console.log("this._formViewPaths", this._formViewPaths); + debugger + let subSchemas = []; + for(const value in this._formViewPaths) { + if(Object.hasOwn(this._formViewPaths, value) && this._formViewPaths[value].schema && this._formViewPaths[value].schema.type === "formlist") { + subSchemas.push(this._formViewPaths[value]) + } + } + return subSchemas; + // return viewPathObj && viewPathObj.component; +} + /** * Returns form schema for a given view path item (path as defined in Data facet) @@ -634,14 +654,18 @@ function processSchema(comp, schema, viewPath, formViewPaths, formModelPaths, mo dataValidations.fromModel = dataValidations.fromModel || {}; dataValidations.toModel = dataValidations.toModel || {}; - if (schema.items) - _processSchemaItems.call(this, comp, schema.items, viewPath, formViewPaths, formModelPaths, modelPathTranslations, dataTranslations, dataValidations); + // if(schema.subSchema && schema.subSchema.items) { + // processSubSchema(schema.subSchema.items) + // } - if (schema.messages) - _processSchemaMessages.call(this, comp, schema.messages); + if (schema.items ) + _processSchemaItems.call(this, comp, schema.items || schema.subSchema.items, viewPath, formViewPaths, formModelPaths, modelPathTranslations, dataTranslations, dataValidations); - if (schema.subscriptions) - _processSchemaSubscriptions.call(this, comp, schema.subscriptions); + if (schema.messages ) + _processSchemaMessages.call(this, comp, schema.messages || (schema.subSchema && schema.subSchema.messages)); + + if (schema.subscriptions || (schema.subSchema && schema.subSchema.subscriptions)) + _processSchemaSubscriptions.call(this, comp, schema.subscriptions || (schema.subSchema && schema.subSchema.subscriptions)); var itemRule = schema.type && formRegistry.get(schema.type); var hostObject = this.getHostObject(); @@ -699,8 +723,8 @@ function processSchema(comp, schema, viewPath, formViewPaths, formModelPaths, mo if (! notInModel) { _addModelPathTranslation(viewPath, modelPath, modelPattern); _addDataTranslation.call(this, translate, 'fromModel', modelPath); - _addDataValidation.call(this, validate, 'toModel', viewPath); - _addDataValidation.call(this, validate, 'fromModel', modelPath); + _addDataValidation.call(this, validate, 'toModel', viewPath, schema); + _addDataValidation.call(this, validate, 'fromModel', modelPath, schema); } } break; @@ -734,7 +758,7 @@ function processSchema(comp, schema, viewPath, formViewPaths, formModelPaths, mo } } - function _addDataValidation(validate, direction, path) { + function _addDataValidation(validate, direction, path, schema) { var validators = validate && validate[direction]; if (! validators) return; @@ -784,6 +808,12 @@ function makeRegexValidator(validatorRegExp) { }; } +function processSubSchema(items) { + items.forEach((comp, index) => { + comp['compName'] = 'milo-' + index; + }) +} + /** * Processes items of the form (or group). From dd837ef001dbeedb0c51c729d8e73b1c7b341cd4 Mon Sep 17 00:00:00 2001 From: SrijanSao Date: Wed, 6 Nov 2024 12:52:25 +0000 Subject: [PATCH 2/9] Refactor --- lib/components/FormList.js | 31 +++++++++++-------------------- lib/forms/Form.js | 28 +++++++--------------------- 2 files changed, 18 insertions(+), 41 deletions(-) diff --git a/lib/components/FormList.js b/lib/components/FormList.js index 929edc0..9874c2e 100644 --- a/lib/components/FormList.js +++ b/lib/components/FormList.js @@ -136,8 +136,8 @@ function MLFormList$clearSubSchemaValidation() { } function MLFormList$validateModel(callback, invalidControls) { - var validations = [] - , self = this; + const validations = [] + const self = this; this._dataValidations = { fromModel: {} }; this.model.m().get().forEach((data, index) => { this._subFormSchema.items.forEach((item) => { @@ -145,8 +145,7 @@ function MLFormList$validateModel(callback, invalidControls) { this._dataValidations.fromModel[`${index}${item.modelPath}`] = [validateRequired]; } }) - }) - + }); _.eachKey(this._dataValidations.fromModel, function (validators, modelPath) { const [index, path] = modelPath.split('.'); @@ -163,7 +162,7 @@ function MLFormList$validateModel(callback, invalidControls) { }, this); - var allValid = true; + let allValid = true; async.each(validations, function (validation, nextValidation) { var lastResponse; @@ -179,7 +178,7 @@ function MLFormList$validateModel(callback, invalidControls) { function (err, valid) { lastResponse.path = validation.modelPath; lastResponse.valid = valid; - createOnValidatedd.call(self, lastResponse, invalidControls); + handleValidatedComponents.call(self, lastResponse, invalidControls); if (!valid) allValid = false; nextValidation(null); } @@ -209,13 +208,13 @@ function MLForm$$validatorResponse(valid, reason, reasonCode) { : { valid: false, reason: reason, reasonCode: reasonCode }; } -function createOnValidatedd(response) { - var reason; - if (response.valid) +function handleValidatedComponents(response) { + if (response.valid) { delete this._invalidFormControls[response.path]; - else { - reason = { - label: `List Item ${response.path}`, + } else { + const [index, modelPath] = response.path.split('.'); + let reason = { + label: `List Item ${Number(index)+1}. ${modelPath}`, reason: response.reason, reasonCode: response.reasonCode }; @@ -223,13 +222,5 @@ function createOnValidatedd(response) { reason: reason }; } - - var data = _.clone(response); - - if (reason) { - data.reason = reason; - delete data.reasonCode; - } - } diff --git a/lib/forms/Form.js b/lib/forms/Form.js index 28b6f7b..0b4e33c 100644 --- a/lib/forms/Form.js +++ b/lib/forms/Form.js @@ -550,8 +550,6 @@ function MLForm$viewPathComponent(viewPath) { * @return {Component} */ function MLForm$getSubSchemas() { - console.log("this._formViewPaths", this._formViewPaths); - debugger let subSchemas = []; for(const value in this._formViewPaths) { if(Object.hasOwn(this._formViewPaths, value) && this._formViewPaths[value].schema && this._formViewPaths[value].schema.type === "formlist") { @@ -559,7 +557,6 @@ function MLForm$getSubSchemas() { } } return subSchemas; - // return viewPathObj && viewPathObj.component; } @@ -654,18 +651,14 @@ function processSchema(comp, schema, viewPath, formViewPaths, formModelPaths, mo dataValidations.fromModel = dataValidations.fromModel || {}; dataValidations.toModel = dataValidations.toModel || {}; - // if(schema.subSchema && schema.subSchema.items) { - // processSubSchema(schema.subSchema.items) - // } - if (schema.items ) - _processSchemaItems.call(this, comp, schema.items || schema.subSchema.items, viewPath, formViewPaths, formModelPaths, modelPathTranslations, dataTranslations, dataValidations); + _processSchemaItems.call(this, comp, schema.items, viewPath, formViewPaths, formModelPaths, modelPathTranslations, dataTranslations, dataValidations); if (schema.messages ) - _processSchemaMessages.call(this, comp, schema.messages || (schema.subSchema && schema.subSchema.messages)); + _processSchemaMessages.call(this, comp, schema.messages); - if (schema.subscriptions || (schema.subSchema && schema.subSchema.subscriptions)) - _processSchemaSubscriptions.call(this, comp, schema.subscriptions || (schema.subSchema && schema.subSchema.subscriptions)); + if (schema.subscriptions) + _processSchemaSubscriptions.call(this, comp, schema.subscriptions); var itemRule = schema.type && formRegistry.get(schema.type); var hostObject = this.getHostObject(); @@ -677,7 +670,6 @@ function processSchema(comp, schema, viewPath, formViewPaths, formModelPaths, mo }; if (itemRule) { - //check(comp.constructor, itemTypes[schema.type].CompClass); itemRule.itemFunction && itemRule.itemFunction.call(hostObject, comp, schema); _processItemTranslations.call(this, viewPath, schema); } else @@ -723,8 +715,8 @@ function processSchema(comp, schema, viewPath, formViewPaths, formModelPaths, mo if (! notInModel) { _addModelPathTranslation(viewPath, modelPath, modelPattern); _addDataTranslation.call(this, translate, 'fromModel', modelPath); - _addDataValidation.call(this, validate, 'toModel', viewPath, schema); - _addDataValidation.call(this, validate, 'fromModel', modelPath, schema); + _addDataValidation.call(this, validate, 'toModel', viewPath); + _addDataValidation.call(this, validate, 'fromModel', modelPath); } } break; @@ -758,7 +750,7 @@ function processSchema(comp, schema, viewPath, formViewPaths, formModelPaths, mo } } - function _addDataValidation(validate, direction, path, schema) { + function _addDataValidation(validate, direction, path) { var validators = validate && validate[direction]; if (! validators) return; @@ -808,12 +800,6 @@ function makeRegexValidator(validatorRegExp) { }; } -function processSubSchema(items) { - items.forEach((comp, index) => { - comp['compName'] = 'milo-' + index; - }) -} - /** * Processes items of the form (or group). From 7c865a4e3ae8f8f648937aac272b4c143d93b9fc Mon Sep 17 00:00:00 2001 From: SrijanSao Date: Wed, 6 Nov 2024 12:58:21 +0000 Subject: [PATCH 3/9] Lint errors and refactor --- lib/components/FormList.js | 11 +++++------ lib/forms/Form.js | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/components/FormList.js b/lib/components/FormList.js index 9874c2e..bf51dc5 100644 --- a/lib/components/FormList.js +++ b/lib/components/FormList.js @@ -1,5 +1,5 @@ 'use strict'; -const async = require('async') +const async = require('async'); const FORMLIST_CHANGE_MESSAGE = 'mlformlistchange'; const MLFormList = module.exports = milo.createComponentClass({ @@ -54,8 +54,7 @@ function handleClick(type, event) { function MLFormList$init() { MLFormList.super.init.apply(this, arguments); this.once('childrenbound', onChildrenBound); - // _manageFormValidation.call(this); - this._invalidFormControls = {} + this._invalidFormControls = {}; } function MLFormList$setItemSchema(schema) { @@ -136,7 +135,7 @@ function MLFormList$clearSubSchemaValidation() { } function MLFormList$validateModel(callback, invalidControls) { - const validations = [] + const validations = []; const self = this; this._dataValidations = { fromModel: {} }; this.model.m().get().forEach((data, index) => { @@ -144,7 +143,7 @@ function MLFormList$validateModel(callback, invalidControls) { if (item.validate && item.validate.fromModel && item.validate.fromModel[0] === 'required') { this._dataValidations.fromModel[`${index}${item.modelPath}`] = [validateRequired]; } - }) + }); }); _.eachKey(this._dataValidations.fromModel, function (validators, modelPath) { @@ -185,7 +184,7 @@ function MLFormList$validateModel(callback, invalidControls) { ); }, function (err) { - invalidControls = {...invalidControls, ...self._invalidFormControls}; + invalidControls = Object.assign({}, invalidControls, self._invalidFormControls); callback && callback({allValid, invalidControls}); } ); diff --git a/lib/forms/Form.js b/lib/forms/Form.js index 0b4e33c..76092af 100644 --- a/lib/forms/Form.js +++ b/lib/forms/Form.js @@ -553,7 +553,7 @@ function MLForm$getSubSchemas() { let subSchemas = []; for(const value in this._formViewPaths) { if(Object.hasOwn(this._formViewPaths, value) && this._formViewPaths[value].schema && this._formViewPaths[value].schema.type === "formlist") { - subSchemas.push(this._formViewPaths[value]) + subSchemas.push(this._formViewPaths[value]); } } return subSchemas; From 95d5144523d4661f185fa0f570699f2490c13107 Mon Sep 17 00:00:00 2001 From: SrijanSao Date: Wed, 6 Nov 2024 14:46:02 +0000 Subject: [PATCH 4/9] Refactor --- lib/components/FormList.js | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/components/FormList.js b/lib/components/FormList.js index bf51dc5..c80892a 100644 --- a/lib/components/FormList.js +++ b/lib/components/FormList.js @@ -15,7 +15,7 @@ const MLFormList = module.exports = milo.createComponentClass({ }, model: undefined, dom: { - cls: ['form-list', 'ml-ui-form-list'] + cls: [ 'form-list', 'ml-ui-form-list' ] }, events: { messages: { @@ -33,7 +33,7 @@ const MLFormList = module.exports = milo.createComponentClass({ } }); -function handleClick(type, event) { +function handleClick (type, event) { const component = milo.Component.getContainingComponent(event.target); if (component && component.name) { const formList = component.getScopeParentWithClass('MLFormList'); @@ -51,13 +51,13 @@ function handleClick(type, event) { } } -function MLFormList$init() { +function MLFormList$init () { MLFormList.super.init.apply(this, arguments); this.once('childrenbound', onChildrenBound); this._invalidFormControls = {}; } -function MLFormList$setItemSchema(schema) { +function MLFormList$setItemSchema (schema) { this._subFormSchema = schema.subSchema; this._movable = !!schema.allowMove; this._deletable = !!schema.allowDelete; @@ -66,18 +66,18 @@ function MLFormList$setItemSchema(schema) { showHidePrepend.call(this); } -function MLFormList$moveItem(fromIndex, toIndex) { +function MLFormList$moveItem (fromIndex, toIndex) { const toInsert = this.model.m.splice(fromIndex, 1); if (toInsert) return this.model.m.splice(toIndex, 0, toInsert[0]); } -function MLFormList$destroy() { +function MLFormList$destroy () { if (this._connector) milo.minder.destroyConnector(this._connector); this._connector = null; MLFormList.super.destroy.apply(this, arguments); } -function onChildrenBound() { +function onChildrenBound () { const scope = this.container.scope; this._connector = milo.minder(this.model, '->>>', scope.list.data).deferChangeMode('<<<->>>'); scope.addBtn && scope.addBtn.events.on('click', { subscriber: addItem, context: this }); @@ -95,46 +95,46 @@ function showHidePrepend() { scope.addBtnBefore.el.classList.toggle('hidden', !this._prepend || !model || model.length === 0); } -function addItem() { +function addItem () { this.model.m.push({}); } -function addItemBefore() { +function addItemBefore () { this.model.m.unshift({}); } -function MLFormList_get() { +function MLFormList_get () { const model = this.model.get(); return model ? _.clone(model) : undefined; } -function MLFormList_set(value) { +function MLFormList_set (value) { this.model.set(value); _triggerExternalPropagation.call(this); } -function MLFormList_del() { +function MLFormList_del () { const res = this.model.set([]); _triggerExternalPropagation.call(this); return res; } -function MLFormList_splice(index, howmany) { +function MLFormList_splice (index, howmany) { const args = [index, howmany].concat(Array.prototype.slice.call(arguments, 2)); this.model.splice.apply(this.model, args); _triggerExternalPropagation.call(this); } -function _triggerExternalPropagation() { +function _triggerExternalPropagation () { this.data.dispatchSourceMessage(FORMLIST_CHANGE_MESSAGE); showHidePrepend.call(this); } -function MLFormList$clearSubSchemaValidation() { +function MLFormList$clearSubSchemaValidation () { this._invalidFormControls = {}; } -function MLFormList$validateModel(callback, invalidControls) { +function MLFormList$validateModel (callback, invalidControls) { const validations = []; const self = this; this._dataValidations = { fromModel: {} }; @@ -166,14 +166,12 @@ function MLFormList$validateModel(callback, invalidControls) { function (validation, nextValidation) { var lastResponse; async.every(validation.validators, - // call validator function (validator, next) { validator(validation.data, function (err, response) { lastResponse = response || {}; next(err, lastResponse.valid); }); }, - // post validation result of item to form function (err, valid) { lastResponse.path = validation.modelPath; lastResponse.valid = valid; @@ -190,9 +188,6 @@ function MLFormList$validateModel(callback, invalidControls) { ); } -/** - * Validation functions - */ function validateRequired(data, callback) { var valid = typeof data != 'undefined' && (typeof data != 'string' || data.trim() != ''); @@ -200,7 +195,6 @@ function validateRequired(data, callback) { callback(null, response); } - function MLForm$$validatorResponse(valid, reason, reasonCode) { return valid ? { valid: true } From 36be16de75a7037a779efbf00f77f170b3c82b8b Mon Sep 17 00:00:00 2001 From: SrijanSao Date: Wed, 6 Nov 2024 14:48:18 +0000 Subject: [PATCH 5/9] Refactor --- lib/components/FormList.js | 2 +- lib/forms/Form.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/components/FormList.js b/lib/components/FormList.js index c80892a..4b976e2 100644 --- a/lib/components/FormList.js +++ b/lib/components/FormList.js @@ -120,7 +120,7 @@ function MLFormList_del () { } function MLFormList_splice (index, howmany) { - const args = [index, howmany].concat(Array.prototype.slice.call(arguments, 2)); + const args = [ index, howmany ].concat(Array.prototype.slice.call(arguments, 2)); this.model.splice.apply(this.model, args); _triggerExternalPropagation.call(this); } diff --git a/lib/forms/Form.js b/lib/forms/Form.js index 76092af..038230e 100644 --- a/lib/forms/Form.js +++ b/lib/forms/Form.js @@ -651,10 +651,10 @@ function processSchema(comp, schema, viewPath, formViewPaths, formModelPaths, mo dataValidations.fromModel = dataValidations.fromModel || {}; dataValidations.toModel = dataValidations.toModel || {}; - if (schema.items ) + if (schema.items) _processSchemaItems.call(this, comp, schema.items, viewPath, formViewPaths, formModelPaths, modelPathTranslations, dataTranslations, dataValidations); - if (schema.messages ) + if (schema.messages) _processSchemaMessages.call(this, comp, schema.messages); if (schema.subscriptions) @@ -670,6 +670,7 @@ function processSchema(comp, schema, viewPath, formViewPaths, formModelPaths, mo }; if (itemRule) { + //check(comp.constructor, itemTypes[schema.type].CompClass); itemRule.itemFunction && itemRule.itemFunction.call(hostObject, comp, schema); _processItemTranslations.call(this, viewPath, schema); } else From a5aba518a59a39215b59bea7abda6827cd9ffa76 Mon Sep 17 00:00:00 2001 From: SrijanSao Date: Wed, 6 Nov 2024 14:50:27 +0000 Subject: [PATCH 6/9] Refactor --- lib/forms/Form.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/forms/Form.js b/lib/forms/Form.js index 038230e..a0d7462 100644 --- a/lib/forms/Form.js +++ b/lib/forms/Form.js @@ -544,10 +544,9 @@ function MLForm$viewPathComponent(viewPath) { } /** - * Returns component for a given view path (path as defined in Data facet) + * Returns subSchemas of type formList * - * @param {String} viewPath - * @return {Component} + * @return {Schemas} */ function MLForm$getSubSchemas() { let subSchemas = []; From 30ce76f43c903721e61f8cf2c0d6d4930b41fb93 Mon Sep 17 00:00:00 2001 From: SrijanSao Date: Wed, 6 Nov 2024 15:43:13 +0000 Subject: [PATCH 7/9] Refactor --- lib/components/FormList.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/components/FormList.js b/lib/components/FormList.js index 4b976e2..76f79c9 100644 --- a/lib/components/FormList.js +++ b/lib/components/FormList.js @@ -148,7 +148,7 @@ function MLFormList$validateModel (callback, invalidControls) { _.eachKey(this._dataValidations.fromModel, function (validators, modelPath) { const [index, path] = modelPath.split('.'); - var data = this.model.m().get()[index][path]; + const data = this.model.m().get()[index][path]; validators = Array.isArray(validators) ? validators : [validators]; if (validators && validators.length) { @@ -164,7 +164,7 @@ function MLFormList$validateModel (callback, invalidControls) { let allValid = true; async.each(validations, function (validation, nextValidation) { - var lastResponse; + let lastResponse; async.every(validation.validators, function (validator, next) { validator(validation.data, function (err, response) { From 133c3f488f963608f84ce45a355d2b8d39a99657 Mon Sep 17 00:00:00 2001 From: SrijanSao Date: Wed, 6 Nov 2024 15:45:05 +0000 Subject: [PATCH 8/9] Refactor --- lib/components/FormList.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/components/FormList.js b/lib/components/FormList.js index 76f79c9..dcf1517 100644 --- a/lib/components/FormList.js +++ b/lib/components/FormList.js @@ -189,9 +189,9 @@ function MLFormList$validateModel (callback, invalidControls) { } function validateRequired(data, callback) { - var valid = typeof data != 'undefined' + const valid = typeof data != 'undefined' && (typeof data != 'string' || data.trim() != ''); - var response = MLForm$$validatorResponse(valid, 'please enter a value', 'REQUIRED'); + const response = MLForm$$validatorResponse(valid, 'please enter a value', 'REQUIRED'); callback(null, response); } From 4f99e498e8977678edd0634c99a419b96b25d6be Mon Sep 17 00:00:00 2001 From: SrijanSao Date: Wed, 6 Nov 2024 15:46:52 +0000 Subject: [PATCH 9/9] Refactor --- lib/components/FormList.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/components/FormList.js b/lib/components/FormList.js index dcf1517..8cdc603 100644 --- a/lib/components/FormList.js +++ b/lib/components/FormList.js @@ -138,7 +138,7 @@ function MLFormList$validateModel (callback, invalidControls) { const validations = []; const self = this; this._dataValidations = { fromModel: {} }; - this.model.m().get().forEach((data, index) => { + (this.model.m().get() || []).forEach((data, index) => { this._subFormSchema.items.forEach((item) => { if (item.validate && item.validate.fromModel && item.validate.fromModel[0] === 'required') { this._dataValidations.fromModel[`${index}${item.modelPath}`] = [validateRequired]; @@ -148,7 +148,7 @@ function MLFormList$validateModel (callback, invalidControls) { _.eachKey(this._dataValidations.fromModel, function (validators, modelPath) { const [index, path] = modelPath.split('.'); - const data = this.model.m().get()[index][path]; + const data = (this.model.m().get() || [])[index][path]; validators = Array.isArray(validators) ? validators : [validators]; if (validators && validators.length) {