-
Notifications
You must be signed in to change notification settings - Fork 566
Character counter #1276
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
Character counter #1276
Conversation
…in repeatable groups
…fault on front-end)
…r views where counter script isn't needed
…using 'characters' counter
|
@jtsternberg @tw2113 Hello. Is there an ETA for a decision on this? I could do with this for a project I'm working on, and wondering whether to roll my own or wait for this to land in core. |
|
@adriantoll None I'm aware of. Feel free to pull in the changes to your own copy of the repo and try out. It'd also aid in testing and making sure nothing would break. |
|
@tw2113 OK, will try to do that in the next few working days and will report back. |
|
@tw2113 I've tried this on a local copy of a client site, both front and back end, and it works well. @gyrus A couple of small points:
|
|
@adriantoll I can look into the spaces issue with the character. The code uses the WP core function from Regarding the |
|
@adriantoll I've added Regarding the spaces in character counting, it looks like the counter's not immediately updating when you type a space at the end of the string - but it updates, including the space, once you type another non-space character. This is because the string is trimmed before the count is done. This seems right, to discount trailing spaces. Let me know if I've missed something though. |
|
Any updates as to whether or not this is in the works to be pulled into CMB2? |
|
@mike-weiner Apart from the minor issues in the CMB2 build process for this (documented above, I assume easily resolved by CMB2 devs), there's nothing from my point of view currently holding it back. |
|
@gyrus great work on this and thank you for your patience. Thanks to all others for testing, it really helps the process and helps to confirm that this is a good addition! I will be merging and making some tweaks to the update, hopefully very soon, but feel free to bump this thread as a reminder if it lags again. |
|
@gyrus This is freaking awesome! Is there anyway to add in an option to his feature to limit a field to a certain type of character along with your character limit? Like alphanumeric only? Etc.? If not, no worries! Thank you for all of the hard work! |
|
@mike-weiner hmm I’d rather not turn this into a validation tool. That’s certainly needed, but a bit out of scope for something like this. A simple fix for validation is to use the html5 validation field types and attributes. |
|
@gyrus there's some cleanup that needs to be done. I will do it, but I ask that you test the cleaned up version with all your existing testing procedures so you can let me know if anything breaks as a result. Some of the things I'll be cleaning up:
|
|
@mike-weiner Agree with @jtsternberg that character type is extending the scope a bit here. But many thanks for your support, glad you like the feature. @jtsternberg Great news! Thanks for the tidy-up, and of course I'm happy to thoroughly test the merged version. Keep us posted. |
|
Yes good point. I removed that in favor of the way we handle other text strings, as well as added the other text strings to be able to be overridden. See the You can see the text ids documented in the changelog entry: https://github.com/CMB2/CMB2/blob/develop/CHANGELOG.md |
|
@gyrus it’s merged/updated. You can test with the development branch. |
|
Ah! Thank you @jtsternberg ! |
|
@jtsternberg Current code in |
* upstream/develop: (93 commits) Ensure to enqueue wp-color-picker Add props for CMB2#1331 Update "develop" bootstrap classname Proposal of CODE OF CONDUCT File Update version/copyright in scripts/stylesheets Fix issues with some tests to get them all passing `CMB2::is_box_type()` now also checks for taxonomies if box is registered to "term" object type. Prepare for 2.7.0 release Add all missing props/udpates to changelog bump tested-to value Rename CMB2_hookup to CMB2_Hookup Fixes CMB2#1328 Validate composer.json Tested Up To confirmations. Update issue templates Add license file to meet Community standards Add changelog for the register_rest_field_cb param Abstract some aspects of the getting/setting of box rest fields to make custom handling easier Add ability to short-circuit the register_rest_field with a callback. Allows registering callback with a different rest slug Oops, send the fallback value to the box_types method Add props for CMB2#1238 Fixes CMB2#1238 by merging with changes, and add CMB2::is_box_type method for checking. Fixes CMB2#1158 Add props for CMB2#1314 minify minify Re-add padding to textareas for readability Fix alpha color picker sample color styling clarify coment limit to 5.3 branch update block editor radio fix initial 5.3 prep work Add new "cmb2_display_class_{$fieldtype}" filter and field "display_class" parameter to allow specifying the class to use to display the field (in admin columns, etc) Fix another place where taxonomy_select_hierarchical was missed Add props for CMB2#1296 & CMB2#1297 Add props for CMB2#1300 Add props for CMB2#1307 Update npm dependencis. Fixes CMB2#1308 Remove grunt-contrib-compress and grunt-combine-media-queries to cut down on npm dependencies taxonomy_select_hierarchical is added in order to save correctly in to database Fix tests broke by introduction of character counter field property Fix issue introduced in 7cb3e00 where field was updated not not returned, breaking things If field has supporting data (e.g. file), add supporting data to field data (i.e supporting field id/value) Add changelog and props for CMB2#1300 Update .min file for CMB2#1300 Add comments to document changes in CMB2#1300 Include .CodeMirror class in sortable exclusions Run the field-specific actions for all fields (including fields in groups). Fixes CMB2#1157 Escaping Improvements to File Base Escaping improvements to File Fields Add changelog and props for CMB2#1276 Refactor character-counter integration ...

Addition of field parameters which provide functionality for character counters, and character limit enforcement.
Description
New field parameters
char_counter:'characters'|'words'char_max: integer. When defined, counter shows remaining chars / words.char_max_msg: string, default:'Your text may be truncated.'char_max_enforce: boolean, default:false. Currently only applied (asmaxlengthattribute) to text and textarea fields which use 'characters' for counter.Motivation and Context
This was a suggested feature which I needed for a project and seemed like a useful addition to the plugin.
Fixes #1241
Risk Level
Medium risk? Has been tested on front-end forms.
Testing procedure
Types of changes
Checklist
IMPORTANT NOTES
cmb2.min.jsisn't currently working. JS all works fine when unminified scripts are used in a dev environment. AFAIK the problem is with the use of_.debounce()incmb2-char-counter.js. This is copied from WP core handling of TinyMCE. The_is available in core. Either Grunt jshint needs modifying so it can recognise core code as being available, or I need an alternative debounce.cmb2.min.jsproperly synched.@sincetags are marked with????placeholder, to be replaced when release version is known.Other notes
wp.utils.WordCounter(), but theword-countcore script is only enqueued when needed. This was throwing an error on pages where main CMB2 JS is included, but there's no fields (e.g. admin dashboard). So I include it with:( wp.utils ? new wp.utils.WordCounter() : {} )Screenshots