Skip to content

Commit

Permalink
Merge pull request #19 from saicheck2233/new_AddURLInputType
Browse files Browse the repository at this point in the history
Enhancement: Add URL input type
  • Loading branch information
saicheck2233 authored Jul 11, 2023
2 parents 95805e3 + 53a1f33 commit ec0701d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ if (typeof brutusin === "undefined") {
"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 (.)",
"url": "The URL provided is not a valid URL.",
"uniqueItems": "Array items must be unique",
"addItem": "Add item",
"true": "True",
Expand Down Expand Up @@ -231,6 +232,8 @@ if (typeof brutusin === "undefined") {
input.type = "email";
} else if (s.format === "password") {
input.type = "password";
} else if (s.format === "url") {
input.type = "url";
} else if (s.format === "text") {
input = document.createElement("textarea");
} else {
Expand Down Expand Up @@ -293,6 +296,12 @@ if (typeof brutusin === "undefined") {
return BrutusinForms.messages["email"];
}
}

if (!s.pattern && s.format === "url") {
if (!value.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/)) {
return BrutusinForms.messages["url"];
}
}
}
if (value !== null && !isNaN(value)) {
if (s.multipleOf && value % s.multipleOf !== 0) {
Expand Down

0 comments on commit ec0701d

Please sign in to comment.