mjda
Well-known member
I've got an add-on that is utilizing JS to count characters in a text input form, so I can display the remaining characters.
Here is the full JS:
In my
Here is the code I'm using to call the JS from my template.
The script works exactly as it's intended in my development site, but doesn't work at all in my production site. It doesn't give an error, or anything. I can verify that the JS is being called, and that the file does exist. I'm thinking there is a problem with how the code is written, that the minify is breaking it. Can someone tell me how I can figure out what's going on here?
Here is the full JS:
JavaScript:
((window, document) =>
{
XF.MyAddonCharCount = XF.Element.newHandler({
textInput: null,
maxLength: null,
charCount: null,
init ()
{
const textInput = this.target
const charCount = textInput.parentElement.querySelector('div.formRow-explain span')
if (!textInput || !charCount)
{
console.error('Cannot initialize, no text input and/or char counter.')
return
}
this.textInput = textInput
this.maxLength = textInput.maxLength
this.charCount = charCount
XF.on(textInput, 'input', this.updateRemainingchars.bind(this))
},
updateRemainingchars()
{
textInput = this.textInput
maxLength = this.maxLength
charCount = this.charCount
const remainingChars = maxLength - textInput.value.length
charCount.textContent = remainingChars
}
})
XF.Element.register('character-counter', 'XF.MyAddonCharCount');
})(window, document)
In my
build.json
, I'm minifying this. Here is the minified code:
JavaScript:
'use strict';((c,d)=>{XF.MyAddonCharCount=XF.Element.newHandler({textInput:null,maxLength:null,charCount:null,init(){const a=this.target,b=a.parentElement.querySelector("div.formRow-explain span");a&&b?(this.textInput=a,this.maxLength=a.maxLength,this.charCount=b,XF.on(a,"input",this.updateRemainingchars.bind(this))):console.error("Cannot initialize, no text input and/or char counter.")},updateRemainingchars(){textInput=this.textInput;maxLength=this.maxLength;charCount=this.charCount;charCount.textContent=
maxLength-textInput.value.length}});XF.Element.register("character-counter","XF.MyAddonCharCount")})(window,document);
Here is the code I'm using to call the JS from my template.
HTML:
<xf:js prod="addon/character-counter.min.js" dev="addon/character-counter.js" />
The script works exactly as it's intended in my development site, but doesn't work at all in my production site. It doesn't give an error, or anything. I can verify that the JS is being called, and that the file does exist. I'm thinking there is a problem with how the code is written, that the minify is breaking it. Can someone tell me how I can figure out what's going on here?
Last edited: