Add more client-side field validation
This commit is contained in:
parent
0961ff2949
commit
21436340cd
@ -716,8 +716,9 @@ SchemaAlignmentDialog._initField = function(inputContainer, mode, initialValue,
|
|||||||
changedCallback();
|
changedCallback();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^\d{4}(-[0-1]\d(-[0-3]\d(T[0-2]\d(:[0-5]\d(:[0-5]\dZ)?)?)?)?)?$/);
|
||||||
} else if (mode === "globe-coordinate") {
|
} else if (mode === "globe-coordinate") {
|
||||||
input.attr("placeholder", "lat/lon");
|
input.attr("placeholder", "lat,lon");
|
||||||
var propagateValue = function(val) {
|
var propagateValue = function(val) {
|
||||||
// TODO add validation here
|
// TODO add validation here
|
||||||
inputContainer.data("jsonValue", {
|
inputContainer.data("jsonValue", {
|
||||||
@ -731,6 +732,7 @@ SchemaAlignmentDialog._initField = function(inputContainer, mode, initialValue,
|
|||||||
changedCallback();
|
changedCallback();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^[\-+]?\d+(\.\d*)?[,\/][\-+]?\d+(\.\d*)?([,\/]\d+(\.\d*)?)?$/);
|
||||||
} else if (mode === "language") {
|
} else if (mode === "language") {
|
||||||
input.attr("placeholder", "lang");
|
input.attr("placeholder", "lang");
|
||||||
input.addClass("wbs-language-input");
|
input.addClass("wbs-language-input");
|
||||||
@ -818,16 +820,22 @@ SchemaAlignmentDialog._initField = function(inputContainer, mode, initialValue,
|
|||||||
});
|
});
|
||||||
if (mode === "amount") {
|
if (mode === "amount") {
|
||||||
input.attr("placeholder", $.i18n._('wikidata-schema')["amount"]);
|
input.attr("placeholder", $.i18n._('wikidata-schema')["amount"]);
|
||||||
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^[\-+]?\d+(\.\d*)?(E[\-+]\d+)?$/);
|
||||||
} else if (mode === "url") {
|
} else if (mode === "url") {
|
||||||
input.attr("placeholder", $.i18n._('wikidata-schema')["full-url"]);
|
input.attr("placeholder", $.i18n._('wikidata-schema')["full-url"]);
|
||||||
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^https?:\/\/.+$/);
|
||||||
} else if (mode === "tabular-data") {
|
} else if (mode === "tabular-data") {
|
||||||
input.attr("placeholder", $.i18n._('wikidata-schema')["tabular-data-with-prefix"]);
|
input.attr("placeholder", $.i18n._('wikidata-schema')["tabular-data-with-prefix"]);
|
||||||
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^Data:.+$/);
|
||||||
} else if (mode === "commonsMedia") {
|
} else if (mode === "commonsMedia") {
|
||||||
input.attr("placeholder", $.i18n._('wikidata-schema')["commons-media"]);
|
input.attr("placeholder", $.i18n._('wikidata-schema')["commons-media"]);
|
||||||
} else if (mode === "math") {
|
} else if (mode === "math") {
|
||||||
input.attr("placeholder", $.i18n._('wikidata-schema')["math-expression"]);
|
input.attr("placeholder", $.i18n._('wikidata-schema')["math-expression"]);
|
||||||
} else if (mode === "geo-shape") {
|
} else if (mode === "geo-shape") {
|
||||||
input.attr("placeholder", $.i18n._('wikidata-schema')["geoshape-with-prefix"]);
|
input.attr("placeholder", $.i18n._('wikidata-schema')["geoshape-with-prefix"]);
|
||||||
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^Data:.+$/);
|
||||||
|
} else {
|
||||||
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^.+$/);
|
||||||
}
|
}
|
||||||
if (mode !== "external-id" &&
|
if (mode !== "external-id" &&
|
||||||
mode !== "url" &&
|
mode !== "url" &&
|
||||||
@ -919,6 +927,19 @@ SchemaAlignmentDialog._initField = function(inputContainer, mode, initialValue,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SchemaAlignmentDialog.setupStringInputValidation = function(input, regex) {
|
||||||
|
input.focus(function() {
|
||||||
|
input.removeClass('wbs-unvalidated-input');
|
||||||
|
}).blur(function() {
|
||||||
|
var currentValue = input.val();
|
||||||
|
if (regex.test(currentValue)) {
|
||||||
|
input.addClass('wbs-validated-input');
|
||||||
|
} else {
|
||||||
|
input.addClass('wbs-unvalidated-input');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
SchemaAlignmentDialog._inputContainerToJSON = function (inputContainer) {
|
SchemaAlignmentDialog._inputContainerToJSON = function (inputContainer) {
|
||||||
var data = inputContainer.data();
|
var data = inputContainer.data();
|
||||||
if (data) {
|
if (data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user