How to tweak the JS codes in the admin panel

I want to add something like this into the control panel JS:

  $('input[type="text"]').on('change', function() {
        $(this).val($(this).val().trim());
    });

Its so frustrating when pasting content in, and it getting rejected due to a space at the start/end of the copied string. How it /usr/local/hestia/web/js/dist/main.min.js compiled? I can’t find a non-minified version ?

We don’t load jQuery anymore so this code willl not work any more but you should be able to paste them in:

web/js/custom_scripts

For now…

We might want to implement it on default …
Then it is web/js/src/

//trim leading / trailing spaces form input fields
export default function trimInput(){
	document.querySelectorAll('input[type="text"]').forEach((input) => {
		input.addEventListener('change', function(){
					this.value=this.value.trim();
		});
	});
}

Should do the trick …

1 Like

Amazing! Do I need to compile anything? I added the new field, and modified index.js, but it doesn’t seem to trigger

You need to run npm run build

Ah ok - from which directory? /usr/local/hestia/web/js/dist ?

I don’t think we include the building on production servers.

If you put it in /web/js/custom_scripts

And change it to:
function trimInput(){
document.querySelectorAll(‘input[type=“text”]’).forEach((input) => {
input.addEventListener(‘change’, function(){
this.value=this.value.trim();
});
});
}
document.onload = trimInput;

It might even work without building.

Or just wait for next release …

Thanks - think I’ll wait on the next release :slight_smile: Good to know its implemented though - its been a PITA a few times now where I’ve missed leading/trailing spaces from a copy and paste, so this should save 1 step :rofl:

I am waiting for the auto test to got trough after that it will get merged …

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.