From df9aa11d4402b57e1dda6f643dbac85eb6a2ddeb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 15 Aug 2021 10:45:17 +0545 Subject: [PATCH] support hyphen and period in custom id component --- public/dist/scripts/app-all.js | 4 ++-- public/dist/scripts/app.js | 4 ++-- public/scripts/views/forms/custom-id.js | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/public/dist/scripts/app-all.js b/public/dist/scripts/app-all.js index b0433ae497..37fa0222b1 100644 --- a/public/dist/scripts/app-all.js +++ b/public/dist/scripts/app-all.js @@ -2384,8 +2384,8 @@ element.setAttribute("data-id-type",idType);info.innerHTML="Appwrite will genera button.className=idType=="custom"?"icon-shuffle copy":"icon-edit copy";} const syncEditorWithID=function(event){if(element.value!=='unique()'||idType!='auto'){writer.value=element.value;} if(idType=='auto'){element.value='unique()';}} -const keypress=function(e){const key=e.which||e.keyCode;const ZERO=48;const NINE=57;const SMALL_A=97;const SMALL_Z=122;const CAPITAL_A=65;const CAPITAL_Z=90;const UNDERSCORE=95;const isNotValidDigit=keyNINE;const isNotValidSmallAlphabet=keySMALL_Z;const isNotValidCapitalAlphabet=keyCAPITAL_Z;if(key==UNDERSCORE&&e.target.value.length==0){e.preventDefault();} -if(key!=UNDERSCORE&&isNotValidDigit&&isNotValidSmallAlphabet&&isNotValidCapitalAlphabet){e.preventDefault();}} +const keypress=function(e){const key=e.which||e.keyCode;const ZERO=48;const NINE=57;const SMALL_A=97;const SMALL_Z=122;const CAPITAL_A=65;const CAPITAL_Z=90;const UNDERSCORE=95;const HYPHEN=45;const PERIOD=46;const isNotValidDigit=keyNINE;const isNotValidSmallAlphabet=keySMALL_Z;const isNotValidCapitalAlphabet=keyCAPITAL_Z;if(key==UNDERSCORE&&e.target.value.length==0){e.preventDefault();} +if(key!=UNDERSCORE&&key!=HYPHEN&&key!=PERIOD&&isNotValidDigit&&isNotValidSmallAlphabet&&isNotValidCapitalAlphabet){e.preventDefault();}} syncEditorWithID();setIdType(idType);writer.addEventListener("change",function(event){element.value=writer.value;});writer.form.addEventListener('reset',function(event){const resetEvent=new Event('reset');element.dispatchEvent(resetEvent);});element.addEventListener('reset',function(event){idType=element.getAttribute('data-id-type');setIdType(idType);});writer.addEventListener('keypress',keypress);button.addEventListener("click",switchType);}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-document",controller:function(element,container,search){var formsDocument=(element.dataset["formsDocument"]||'');var searchButton=(element.dataset["search"]||0);let path=container.scope(searchButton);element.addEventListener('click',function(){search.selected=element.value;search.path=path;document.dispatchEvent(new CustomEvent(formsDocument,{bubbles:false,cancelable:true}));});}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-document-preview",controller:function(element,container,search){element.addEventListener('change',function(){console.log(element.value);});}});})(window);(function(window){window.ls.container.get("view").add({selector:"data-forms-filter",controller:function(document,container,expression,element,form,di){let name=element.dataset["formsFilter"]||"";let events=element.dataset["event"]||"";let serialize=function(obj,prefix){let str=[],p;for(p in obj){if(obj.hasOwnProperty(p)){let k=prefix?prefix+"["+p+"]":p,v=obj[p];if(v===""){continue;} str.push(v!==null&&typeof v==="object"?serialize(v,k):encodeURIComponent(k)+"="+encodeURIComponent(v));}} return str.join("&");};let parse=function(filter){if(filter===""){return null;} diff --git a/public/dist/scripts/app.js b/public/dist/scripts/app.js index fbaf23c857..ef81cd86e8 100644 --- a/public/dist/scripts/app.js +++ b/public/dist/scripts/app.js @@ -368,8 +368,8 @@ element.setAttribute("data-id-type",idType);info.innerHTML="Appwrite will genera button.className=idType=="custom"?"icon-shuffle copy":"icon-edit copy";} const syncEditorWithID=function(event){if(element.value!=='unique()'||idType!='auto'){writer.value=element.value;} if(idType=='auto'){element.value='unique()';}} -const keypress=function(e){const key=e.which||e.keyCode;const ZERO=48;const NINE=57;const SMALL_A=97;const SMALL_Z=122;const CAPITAL_A=65;const CAPITAL_Z=90;const UNDERSCORE=95;const isNotValidDigit=keyNINE;const isNotValidSmallAlphabet=keySMALL_Z;const isNotValidCapitalAlphabet=keyCAPITAL_Z;if(key==UNDERSCORE&&e.target.value.length==0){e.preventDefault();} -if(key!=UNDERSCORE&&isNotValidDigit&&isNotValidSmallAlphabet&&isNotValidCapitalAlphabet){e.preventDefault();}} +const keypress=function(e){const key=e.which||e.keyCode;const ZERO=48;const NINE=57;const SMALL_A=97;const SMALL_Z=122;const CAPITAL_A=65;const CAPITAL_Z=90;const UNDERSCORE=95;const HYPHEN=45;const PERIOD=46;const isNotValidDigit=keyNINE;const isNotValidSmallAlphabet=keySMALL_Z;const isNotValidCapitalAlphabet=keyCAPITAL_Z;if(key==UNDERSCORE&&e.target.value.length==0){e.preventDefault();} +if(key!=UNDERSCORE&&key!=HYPHEN&&key!=PERIOD&&isNotValidDigit&&isNotValidSmallAlphabet&&isNotValidCapitalAlphabet){e.preventDefault();}} syncEditorWithID();setIdType(idType);writer.addEventListener("change",function(event){element.value=writer.value;});writer.form.addEventListener('reset',function(event){const resetEvent=new Event('reset');element.dispatchEvent(resetEvent);});element.addEventListener('reset',function(event){idType=element.getAttribute('data-id-type');setIdType(idType);});writer.addEventListener('keypress',keypress);button.addEventListener("click",switchType);}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-document",controller:function(element,container,search){var formsDocument=(element.dataset["formsDocument"]||'');var searchButton=(element.dataset["search"]||0);let path=container.scope(searchButton);element.addEventListener('click',function(){search.selected=element.value;search.path=path;document.dispatchEvent(new CustomEvent(formsDocument,{bubbles:false,cancelable:true}));});}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-document-preview",controller:function(element,container,search){element.addEventListener('change',function(){console.log(element.value);});}});})(window);(function(window){window.ls.container.get("view").add({selector:"data-forms-filter",controller:function(document,container,expression,element,form,di){let name=element.dataset["formsFilter"]||"";let events=element.dataset["event"]||"";let serialize=function(obj,prefix){let str=[],p;for(p in obj){if(obj.hasOwnProperty(p)){let k=prefix?prefix+"["+p+"]":p,v=obj[p];if(v===""){continue;} str.push(v!==null&&typeof v==="object"?serialize(v,k):encodeURIComponent(k)+"="+encodeURIComponent(v));}} return str.join("&");};let parse=function(filter){if(filter===""){return null;} diff --git a/public/scripts/views/forms/custom-id.js b/public/scripts/views/forms/custom-id.js index 304f780000..c6dd7e37b7 100644 --- a/public/scripts/views/forms/custom-id.js +++ b/public/scripts/views/forms/custom-id.js @@ -114,6 +114,8 @@ const CAPITAL_A = 65; const CAPITAL_Z = 90; const UNDERSCORE = 95; + const HYPHEN = 45; + const PERIOD = 46; const isNotValidDigit = key < ZERO || key > NINE; const isNotValidSmallAlphabet = key < SMALL_A || key > SMALL_Z; @@ -123,7 +125,7 @@ if (key == UNDERSCORE && e.target.value.length == 0) { e.preventDefault(); } - if (key != UNDERSCORE && isNotValidDigit && isNotValidSmallAlphabet && isNotValidCapitalAlphabet) { + if (key != UNDERSCORE && key != HYPHEN && key != PERIOD && isNotValidDigit && isNotValidSmallAlphabet && isNotValidCapitalAlphabet) { e.preventDefault(); } }