Last active
January 5, 2026 19:55
-
-
Save nicobytes/b9207658e33ab6012d99ae314f62b24d to your computer and use it in GitHub Desktop.
Url Custom Field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #set($titleVarName="titolo") | |
| #set($urlVarName="urltitle") | |
| <script> | |
| function updateDisplayURLTitle(titleValue, urlTitleFieldName, displayElement){ | |
| // get the title entered by the user | |
| if(!titleValue || titleValue.length == 0){ | |
| displayElement.innerHTML = ""; | |
| DotCustomFieldApi.set(urlTitleFieldName, ""); | |
| return; | |
| } | |
| var urlTitle = titleValue.toLowerCase(); | |
| urlTitle= urlTitle.replace(/^\s+|\s+$/g,""); | |
| urlTitle = urlTitle.replace(/[^a-zA-Z 0-9]+/g,' '); | |
| urlTitle = urlTitle.replace(/\s/g, "-"); | |
| // Replace multiple consecutive dashes with a single dash | |
| urlTitle = urlTitle.replace(/-{2,}/g, '-'); | |
| // Remove trailing dashes | |
| urlTitle = urlTitle.replace(/-+$/, ''); | |
| // Remove leading dashes | |
| urlTitle = urlTitle.replace(/^-+/, ''); | |
| displayElement.innerHTML = urlTitle; | |
| DotCustomFieldApi.set(urlTitleFieldName, urlTitle); | |
| } | |
| DotCustomFieldApi.ready(() => { | |
| const titleFieldName = '$titleVarName'; | |
| const urlTitleFieldName = '$urlVarName'; | |
| const displayElement = document.getElementById("displayURLTitle"); | |
| // Initial update | |
| const initialTitleValue = DotCustomFieldApi.get(titleFieldName) || ''; | |
| updateDisplayURLTitle(initialTitleValue, urlTitleFieldName, displayElement); | |
| // Watch for changes | |
| DotCustomFieldApi.onChangeField(titleFieldName, value => { | |
| updateDisplayURLTitle(value || '', urlTitleFieldName, displayElement); | |
| }); | |
| }); | |
| </script> | |
| <div id="displayURLTitle" style="height:20px"> </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment