Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The module uses a HTML attribute of maxlength_js_label, which is not valid.
In HTML5 you could use data- prefixed attributes, but that doesn't help for non-HTML5 sites.
Comment | File | Size | Author |
---|---|---|---|
#13 | maxlength-invalid_html-1680096-13.patch | 4.6 KB | frjo |
#1 | maxlength-invalid_html-1680096-1.patch | 1.76 KB | Loparev |
Comments
Comment #1
Loparev CreditAttribution: Loparev commentedHi. I ran into this problem to. I hope, this patch will be useful for those guys who respect html5 markup standards.
Comment #2
Loparev CreditAttribution: Loparev commentedComment #3
BR0kENWhy not
$(this).data('maxlength_js_label')
?Comment #4
Loparev CreditAttribution: Loparev commented@BR0kEN because:
1. Custom attributes should be named like 'data-custom-attribute-name'.
2. To get first point I have changed all
maxlength_js_label
attributes todata-maxlength_js_label
. So from js this label string available indata-maxlength_js_label
attributeComment #5
Loparev CreditAttribution: Loparev commentedSorry, your question was about
attr()
anddata()
methods.I used
attr()
instead ofdata()
becausedata-maxlength_js_label
value is permanent and it will never changed by calling data('data-maxlength_js_label', 'some-new-value'), so$(this).attr('data-maxlength_js_label')
will always return actual value.Comment #6
BR0kEN@Loparev, the
data()
method works as getter and setter. If value never changed, then it will return actual value too.Comment #7
Loparev CreditAttribution: Loparev commented@BR0kEN, I know it.
Difference beetween data() and attr() methods:
So in my case it is not important: use
data()
orattr()
, because value will never changed.By the way,
attr()
was in original maxlength.js file. So it is second reason why I usedattr()
method.Comment #8
BR0kENI know it too, @Loparev.
But
data()
designed to work withdata-*
attributes and it is logical. Take your code, replace$('#id').data('test', 'edited-test');
by$('#id').attr('data-test', 'edited-test');
and you've get another result.P.S. Doesn't matter that you'll found in a module's code: you need trying to find the best approaches and doesn't think that legacy code is pretty and untouchable. But it is your patch, your thread, your decision, your approach, and all these up on you.
Comment #9
rooby CreditAttribution: rooby commentedIn this case I think either attr() or data() is fine.
A lot of people use attr() for simple string data that is pre-existing on the DOM and data() for more complex data or data that isn't already on the DOM when the page loads.
Comment #10
Loparev CreditAttribution: Loparev commented@rooby, could you please review and test this patch?
Comment #11
rooby CreditAttribution: rooby commentedI'm just about to go to sleep now but I should be able to test it in the next day or two.
Comment #12
Loparev CreditAttribution: Loparev commentedsure, sorry. I meant in nearest future
Comment #13
frjo CreditAttribution: frjo commentedUpdated the patch so it apply cleanly on 7.x-3.x, uses data() instead of attr() and also fixes class names by replacing underscores with hyphen.
Comment #14
cedeweyWe are only maintaining the Drupal 7 version of the module for critical security fixes, so I'm marking this Closed (won't fix). Thank you for working on this issue. If you do want to maintain the Drupal 7 version, do reach out. We'd be happy to bring you on board as a maintainer.
I also encourage you, if you haven't already, to upgrade your site to Drupal 8/9. We are actively maintaining that version and you would enjoy all of the other features of the latest version of Drupal.