From c1d5bb490cb390d1123c73f173291790e775e8af Mon Sep 17 00:00:00 2001 From: "Jason.Chuah" Date: Mon, 26 Jun 2023 23:27:09 +0800 Subject: [PATCH 1/4] issue#90: email validation does not work --- src/js/brutusin-json-forms.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 49ee5ea..cd203f6 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -277,6 +277,13 @@ if (typeof brutusin === "undefined") { return BrutusinForms.messages["maxLength"].format(s.maxLength); } } + //Add a default regex pattern matching for email validation, or else user could use + //the `pattern` field for their own custom regex pattern + if (!s.pattern && s.format === "email") { + if (!value.match(/[^@\s]+@[^@\s]+\.[^@\s]+/)) { + return BrutusinForms.messages["email"]; + } + } } if (value !== null && !isNaN(value)) { if (s.multipleOf && value % s.multipleOf !== 0) { From 93c14eb2c69570cd364d10bbb43d344fd3ffc634 Mon Sep 17 00:00:00 2001 From: "Jason.Chuah" Date: Tue, 27 Jun 2023 10:47:01 +0800 Subject: [PATCH 2/4] issue#103 Adding new item to an array doesnt show default values when Initial Data is passed --- src/js/brutusin-json-forms.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 49ee5ea..f1da237 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -1200,6 +1200,9 @@ if (typeof brutusin === "undefined") { if (!value) { if (typeof initialValue !== "undefined" && initialValue !== null) { value = getInitialValue(id); + if (value === null && typeof s.default !== "undefined") { + value = s.default; + } } else { value = s.default; } From f97020f1241dc52862991b0f13dd7da7da5b5918 Mon Sep 17 00:00:00 2001 From: "Jason.Chuah" Date: Tue, 27 Jun 2023 11:35:45 +0800 Subject: [PATCH 3/4] add email validation error message --- src/js/brutusin-json-forms.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index cd203f6..a3c021e 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -76,6 +76,7 @@ if (typeof brutusin === "undefined") { "exclusiveMaximum": "Value must be **lower than** `{0}`", "minProperties": "At least `{0}` properties are required", "maxProperties": "At most `{0}` properties are allowed", + "email": "The email must at least consists an asterisk (@), following by a domain name with a dot (.)", "uniqueItems": "Array items must be unique", "addItem": "Add item", "true": "True", From 05040292ce1fc2798f196fa48e40e126ae64137e Mon Sep 17 00:00:00 2001 From: "Jason.Chuah" Date: Tue, 27 Jun 2023 12:45:54 +0800 Subject: [PATCH 4/4] issue95&108 --- src/js/brutusin-json-forms.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 49ee5ea..f64ae86 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -252,9 +252,15 @@ if (typeof brutusin === "undefined") { if (parentSchema && parentSchema.type === "object") { if (parentSchema.required) { return BrutusinForms.messages["required"]; + } else if (parentSchema.requiredProperties) { + for (var i = 0; i < parentSchema.requiredProperties.length; i++) { + if (parentSchema.requiredProperties[i] === s.$id.substring(2)) { + return BrutusinForms.messages["required"]; + } + } } else { for (var prop in parentObject) { - if (parentObject[prop] !== null) { + if (parentObject[prop] === null) { return BrutusinForms.messages["required"]; } }