Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added counter for input fields with maximum-length attribute #2950

Merged
merged 3 commits into from
Jan 19, 2023
Merged

Added counter for input fields with maximum-length attribute #2950

merged 3 commits into from
Jan 19, 2023

Conversation

sreichel
Copy link
Contributor

@sreichel sreichel commented Jan 16, 2023

Description (*)

Adds js-snippet to ...

  • admin product edit page
  • admin product attributes edit page
  • admin config section

... to show how many chars are left for valid input.

Note: requires validate-length and maximum-length-XXX attribute

counter

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

@github-actions github-actions bot added Component: Adminhtml Relates to Mage_Adminhtml Component: Admin Relates to Mage_Admin JavaScript Relates to js/* Template : admin Relates to admin template labels Jan 16, 2023
@justinbeaty
Copy link
Contributor

Nice quality of life feature! My only suggestion is to style it like this, which I think is more standard UI.

image

        // display the value, run once at load and on each observed keyup
        countdown: function(element) {
            var elm = $(element);
            var curLen = elm.getValue().length;
            var maxLen = elm.retrieve('maxLen');
            var count  = maxLen - curLen;
            var counter = elm.retrieve('counter');
            counter.update(' (' + curLen + '/' + maxLen + ')');
            if (curLen > maxLen) {
                counter.setStyle({'color': 'red'});
            } else {
                counter.setStyle({'color': 'inherit'});
            }
            return elm;
        }

I also changed the conditional to just > instead of >= because I was allowed to save an attribute with code with exactly 30 characters, despite the note: "Maximum length of attribute code must be less then 30 symbols" (unrelated, there's also a typo there, should be "than").

@justinbeaty justinbeaty mentioned this pull request Jan 16, 2023
4 tasks
justinbeaty
justinbeaty previously approved these changes Jan 16, 2023
fballiano
fballiano previously approved these changes Jan 17, 2023
@sreichel sreichel dismissed stale reviews from fballiano and justinbeaty via 04d69f3 January 18, 2023 01:10
Co-authored-by: Ng Kiat Siong <kiatsiong.ng@gmail.com>
@fballiano fballiano merged commit 412d44f into OpenMage:1.9.4.x Jan 19, 2023
@fballiano
Copy link
Contributor

merged and v20ed

@luigifab
Copy link
Contributor

luigifab commented Jan 19, 2023

This create a bug: document.observe('dom:loaded',
This is a prototype way, if you merge and minify all js files in one, this will crash:
Uncaught TypeError: document.observe is not a function

(okay I got this with a custom module...)

@fballiano
Copy link
Contributor

@luigifab if you change that line with Event.observe(window, 'load', function() { does it work?

@sreichel
Copy link
Contributor Author

Changing to Event.observe(window, 'load', function() { works for me w/ merged JS files too.

@luigifab PR ready if confirmed.

@luigifab
Copy link
Contributor

luigifab commented Jan 20, 2023

No, but with window.addEventListener('load', function() { it's ok, and it works on new product attribute page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Admin Relates to Mage_Admin Component: Adminhtml Relates to Mage_Adminhtml JavaScript Relates to js/* new feature Template : admin Relates to admin template
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants