westonganger / input-case-enforcer

Enforce uppercase, lowercase, or Capitalized inputs & textareas

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Javascript vanilla

urufudev opened this issue · comments

will there be any possibility to do it in javascript without jquery?
i love this package

For my own curiousity and learning I am attempting to do this in #4. This project is a good candidate for the experiment as its a pretty small codebase.

Something I notice right away after putting in a little effort is that the public API of the library changes just to accommodate vanilla JS. So it would be next to impossible to develop jquery/vanilla in tandem.

Other main issue I note is that namespaced events are not built-in to plain JS so requires some hackery.

Tracking the discussion for namespaced jquery events here, HubSpot/youmightnotneedjquery#309

I've created an experimental version of this in Vanilla Js called input-case-enforcer-no-jquery, it's currently attached to the window. I opened a pull request for it. Please let me know if there needs to be any adjustment for the PR to get accepted.

I've created an experimental version of this in Vanilla Js called input-case-enforcer-no-jquery, it's currently attached to the window. I opened a pull request for it. Please let me know if there needs to be any adjustment for the PR to get accepted.

Hello. I tried your .js, but when I use it identifying by class name, it only works on the first input, and not on the rest.

<script> document.addEventListener("DOMContentLoaded", function() { window.inputCaseEnforcer.init('.bestupper', 'uppercase'); }); </script>

@urufudev Thanks for trying it out. It currently uses document.querySelector() rather than document.querySelectorAll(), so it would need to specify an ID, or it'll only use the first instance of a class name. I will work on adding support for multiple classes with document.querySelectorAll() in the near future!

@urufudev I've pushed a new version of mine, it should be working now for multiple classes. I tested the main functions which is detailed in the demonstration file index-no-query.html by using window.inputCaseEnforcer.init('.enforced-uppercase', 'uppercase');. Please let me know if that works for you.

@urufudev I've pushed a new version of mine, it should be working now for multiple classes. I tested the main functions which is detailed in the demonstration file index-no-query.html by using window.inputCaseEnforcer.init('.enforced-uppercase', 'uppercase');. Please let me know if that works for you.

Thanks, work's fine 😄