question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: max-length and different markup for overlength text

See original GitHub issue

I want to impose a max-length for some of my inputs. But instead of truncating the entered (or pasted) text, I want to apply a different style to that part of the text (at the end of the input field) which causes the overlength. In fact, just like twitter does.

Example (maxlength 3): Too long Adding "Way " to the beginning should result in: Way too long

Is there a mechanism or an easy way to achieve this with draft.js? I already know that I can retrieve the current input length via editorState.getCurrentContent().getPlainText('').length.

Thanks for any suggestions!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rommguycommented, Dec 19, 2017

@dtipson checkout this - how to limit draftJS text I haven’t tried it myself yet, but planning to do so

1reaction
dtipsoncommented, Apr 1, 2017

Dynamically adding readOnly also doesn’t seem to help (and in theory wouldn’t be right anyhow, as a maxlength should allow deletion, just not addition). This seems like a pretty basic feature for any text field, so I feel like I’m missing something obvious.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML attribute: maxlength - MDN Web Docs
The maxlength attribute defines the maximum number of characters (as UTF-16 code units) the user can enter into an <input> or <textarea> ....
Read more >
Do not count html markup [#1027966] | Drupal.org
The counted length of visible characters doesn't always match 100% with the real length of the text. On a maxlength of 4000 I...
Read more >
Difference between "maxlength" & "size" attribute in html?
The maxlength (not max-length ) attribute specifies the maximum length of the input string in characters or, more exactly, in code units.
Read more >
eCRAFT Periodic Report Utility (ePRU) Vendor User Guide
Changed required fields to red text throughout, added/modified ... ePRU workbook conform to standard editing, navigation, and other ...
Read more >
input type=password – password-input field - HTML5
Specifies that its input element is a one-line plain-text edit control for entering a password. i maxlength = positive integer #: The maximum...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found