diff --git a/ayanova/src/api/gzform.js b/ayanova/src/api/gzform.js index 0535b061..8340d72e 100644 --- a/ayanova/src/api/gzform.js +++ b/ayanova/src/api/gzform.js @@ -817,7 +817,7 @@ export default { //that did NOT pass the truthy test function //de-lodash - // let m = window.$gz._.remove(vm.formState.serverError.details, function( + // let m = window.$gz. _.remove(vm.formState.serverError.details, function( // o // ) { // if (!o.target) { diff --git a/ayanova/src/api/gzutil.js b/ayanova/src/api/gzutil.js index c94060ad..33294525 100644 --- a/ayanova/src/api/gzutil.js +++ b/ayanova/src/api/gzutil.js @@ -182,8 +182,42 @@ export default { // Clean up a tag with same rules as server // normalizeTag: function(tagName) { + /* + SERVER VERSION + public static string NormalizeTag(string inObj) + { + if (string.IsNullOrWhiteSpace(inObj)) return null; + //Must be lowercase per rules + //This may be naive when we get international cust omers but for now supporting utf-8 and it appears it's safe to do this with unicode + inObj = inObj.ToLowerInvariant(); + //No spaces in tags, replace with dashes + inObj = inObj.Replace(" ", "-"); + //Remove multiple dash sequences + inObj = System.Text.RegularExpressions.Regex.Replace(inObj, "-+", "-"); + //Ensure doesn't start or end with a dash + inObj = inObj.Trim('-'); + //No longer than 255 characters + inObj = StringUtil.MaxLength(inObj, 255); + return inObj; + } + */ + //de-lodash //kebab case takes care of all the things we need for tags in one go - tagName = window.$gz._.kebabCase(tagName); + // tagName = window.$gz._.kebabCase(tagName); + + if (!tagName || tagName == "") { + return null; + } + tagName = tagName.toLowerCase(); + + //spaces to dashes + tagName = tagName.replace(/ /gi, "-"); + + //multiple dashes to single dashes + tagName = tagName.replace(/-+/g, "-"); + + //ensure doesn't start or end with a dash + tagName = this.trimSpecific(tagName, "-"); //No longer than 255 characters tagName = tagName.length > 255 ? tagName.substr(0, 255 - 1) : tagName; @@ -414,6 +448,16 @@ export default { objectIsEmpty: function(obj) { //https://stackoverflow.com/a/4994265/8939 return Object.keys(obj).length === 0; + }, + /////////////////////////////////////////////// + // Trim specific character from start and end + // + trimSpecific: function trim(str, ch) { + var start = 0, + end = str.length; + while (start < end && str[start] === ch) ++start; + while (end > start && str[end - 1] === ch) --end; + return start > 0 || end < str.length ? str.substring(start, end) : str; } /**