From 5e096f13074faf9ce6796aefa2e63a89cb1f983d Mon Sep 17 00:00:00 2001 From: Tony Atkins Date: Tue, 25 Jun 2019 09:50:38 +0200 Subject: [PATCH 1/4] Updated forward-facing version following 2.1.0 release. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e5746a..4a3ae00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gpii-json-schema", - "version": "2.1.0", + "version": "2.1.1", "description": "Support validation of JSON within the Fluid and GPII ecosystems.", "main": "index.js", "scripts": { From 83e2f440e9243235357b9704c58625c3b5b746cb Mon Sep 17 00:00:00 2001 From: Tony Atkins Date: Thu, 27 Jun 2019 15:58:47 +0200 Subject: [PATCH 2/4] GPII-3921: Converted direct options call to use IoC. --- src/js/client/errorBinder.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/client/errorBinder.js b/src/js/client/errorBinder.js index 146e924..facf1de 100644 --- a/src/js/client/errorBinder.js +++ b/src/js/client/errorBinder.js @@ -38,7 +38,7 @@ invokers: { renderErrors: { funcName: "gpii.schema.client.errorAwareForm.renderErrors", - args: ["{that}", "{renderer}"] + args: ["{that}", "{renderer}", "{that}.options.templateKeys.inlineError"] // renderer, inlineErrorTemplateKey } }, modelListeners: { @@ -62,8 +62,8 @@ }; // We need to ensure that both our own markup and the field errors are rendered before we fire `onMarkupRendered`. - gpii.schema.client.errorAwareForm.renderErrors = function (that, renderer) { - var templateExists = fluid.get(that, ["model", "templates", "pages", that.options.templateKeys.inlineError]); + gpii.schema.client.errorAwareForm.renderErrors = function (that, renderer, inlineErrorTemplateKey) { + var templateExists = fluid.get(that, ["model", "templates", "pages", inlineErrorTemplateKey]); if (templateExists && renderer) { // Get rid of any previous validation errors. that.locate("fieldError").remove(); @@ -77,7 +77,7 @@ var bindingPath = fluid.get(value, "path") || value; fluid.each(that.model.validationResults.errors, function (error) { if (gpii.schema.client.elPathsEqual(error.dataPath, bindingPath)) { - that.renderer.before(fieldElement, that.options.templateKeys.inlineError, error); // element, key, context + that.renderer.before(fieldElement, inlineErrorTemplateKey, error); // element, key, context } }); } From beab13f1b667a85d979de0d6f19e17e26dcd8c3c Mon Sep 17 00:00:00 2001 From: Tony Atkins Date: Fri, 28 Jun 2019 09:17:35 +0200 Subject: [PATCH 3/4] GPII-3921: Further insulated error binder to avoid errors during the initial validation phase. --- src/js/client/errorBinder.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/js/client/errorBinder.js b/src/js/client/errorBinder.js index facf1de..4f3cc2a 100644 --- a/src/js/client/errorBinder.js +++ b/src/js/client/errorBinder.js @@ -38,7 +38,7 @@ invokers: { renderErrors: { funcName: "gpii.schema.client.errorAwareForm.renderErrors", - args: ["{that}", "{renderer}", "{that}.options.templateKeys.inlineError"] // renderer, inlineErrorTemplateKey + args: ["{that}", "{renderer}", "{that}.options.templateKeys.inlineError", "{that}.locate"] // renderer, inlineErrorTemplateKey, locator } }, modelListeners: { @@ -62,22 +62,22 @@ }; // We need to ensure that both our own markup and the field errors are rendered before we fire `onMarkupRendered`. - gpii.schema.client.errorAwareForm.renderErrors = function (that, renderer, inlineErrorTemplateKey) { + gpii.schema.client.errorAwareForm.renderErrors = function (that, renderer, inlineErrorTemplateKey, locator) { var templateExists = fluid.get(that, ["model", "templates", "pages", inlineErrorTemplateKey]); - if (templateExists && renderer) { + if (templateExists && renderer && locator) { // Get rid of any previous validation errors. - that.locate("fieldError").remove(); + locator("fieldError").remove(); if (fluid.get(that, "model.validationResults.isValid") === false) { // Step through the list of bindings and look for anything that matches the current validation errors. fluid.each(that.options.errorBindings, function (value, key) { var selector = fluid.get(value, "selector") || key; - var fieldElement = that.locate(selector); + var fieldElement = locator(selector); if (fieldElement) { var bindingPath = fluid.get(value, "path") || value; fluid.each(that.model.validationResults.errors, function (error) { if (gpii.schema.client.elPathsEqual(error.dataPath, bindingPath)) { - that.renderer.before(fieldElement, inlineErrorTemplateKey, error); // element, key, context + renderer.before(fieldElement, inlineErrorTemplateKey, error); // element, key, context } }); } From 5d7b38cbbfd7863891bde84fa8d0e7bb0249d108 Mon Sep 17 00:00:00 2001 From: Tony Atkins Date: Fri, 28 Jun 2019 10:44:20 +0200 Subject: [PATCH 4/4] GPII-3994: Improved model component validation lifecycle and removed IoC workarounds from error binder. --- src/js/client/errorBinder.js | 15 +++++++-------- src/js/common/schemaValidatedModelComponent.js | 8 +++++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/js/client/errorBinder.js b/src/js/client/errorBinder.js index 4f3cc2a..5731d64 100644 --- a/src/js/client/errorBinder.js +++ b/src/js/client/errorBinder.js @@ -11,7 +11,6 @@ https://github.com/the-t-in-rtf/gpii-json-schema/blob/master/docs/validator.md */ -/* globals fluid */ (function () { "use strict"; var gpii = fluid.registerNamespace("gpii"); @@ -38,7 +37,7 @@ invokers: { renderErrors: { funcName: "gpii.schema.client.errorAwareForm.renderErrors", - args: ["{that}", "{renderer}", "{that}.options.templateKeys.inlineError", "{that}.locate"] // renderer, inlineErrorTemplateKey, locator + args: ["{that}", "{renderer}"] // renderer } }, modelListeners: { @@ -62,22 +61,22 @@ }; // We need to ensure that both our own markup and the field errors are rendered before we fire `onMarkupRendered`. - gpii.schema.client.errorAwareForm.renderErrors = function (that, renderer, inlineErrorTemplateKey, locator) { - var templateExists = fluid.get(that, ["model", "templates", "pages", inlineErrorTemplateKey]); - if (templateExists && renderer && locator) { + gpii.schema.client.errorAwareForm.renderErrors = function (that, renderer) { + var templateExists = fluid.get(that, ["model", "templates", "pages", that.options.templateKeys.inlineError]); + if (templateExists && renderer) { // Get rid of any previous validation errors. - locator("fieldError").remove(); + that.locate("fieldError").remove(); if (fluid.get(that, "model.validationResults.isValid") === false) { // Step through the list of bindings and look for anything that matches the current validation errors. fluid.each(that.options.errorBindings, function (value, key) { var selector = fluid.get(value, "selector") || key; - var fieldElement = locator(selector); + var fieldElement = that.locate(selector); if (fieldElement) { var bindingPath = fluid.get(value, "path") || value; fluid.each(that.model.validationResults.errors, function (error) { if (gpii.schema.client.elPathsEqual(error.dataPath, bindingPath)) { - renderer.before(fieldElement, inlineErrorTemplateKey, error); // element, key, context + renderer.before(fieldElement, that.options.templateKeys.inlineError, error); // element, key, context } }); } diff --git a/src/js/common/schemaValidatedModelComponent.js b/src/js/common/schemaValidatedModelComponent.js index 1d44969..d7a8501 100644 --- a/src/js/common/schemaValidatedModelComponent.js +++ b/src/js/common/schemaValidatedModelComponent.js @@ -74,7 +74,13 @@ var fluid = fluid || require("infusion"); }, modelListeners: { "*": { - excludeSource: "validation", + excludeSource: ["init", "validation"], + funcName: "gpii.schema.modelComponent.validateModel", + args: ["{gpii.schema.validator}", "{that}"] // globalValidator, validatedModelComponent + } + }, + listeners: { + "onCreate.validate": { funcName: "gpii.schema.modelComponent.validateModel", args: ["{gpii.schema.validator}", "{that}"] // globalValidator, validatedModelComponent }