jonom/silverstripe-text-target-length

Set character length recommendations on SilverStripe text form fields

Fund package maintenance!
jonom
www.paypal.me/jmnz

Installs: 48 335

Dependents: 8

Suggesters: 1

Security: 0

Stars: 30

Watchers: 4

Forks: 14

Open Issues: 5

Type:silverstripe-vendormodule

2.0.2 2018-05-28 17:57 UTC

This package is auto-updated.

Last update: 2021-08-27 20:10:30 UTC


README

Character limits in action

If you see a field marked 'Description' you know roughly what type of content to put in there. But how do you know how much of it to write? A single sentence might do, but maybe a paragraph or more is required? A great content plan should recommend an ideal length for every type of content, so content authors and designers alike can make informed decisions.

This module extends the TextField, TextareaField and HTMLEditorField classes in SilverStripe to allow you to set a recommended content length, and set soft upper and lower limits on character count.

Requirements

SilverStripe 4.0+ (3.1+ in previous releases)

Installation

Composer (best practice)

Packagist listing and installation instructions

How to use

With the module installed you can call call setTargetLength() on TextField, TextareaField and HTMLEditorField form fields.

// Ideal length: 100 characters
// Minimum: 75 (automatically set at 75% of ideal)
// Maximum: 125 (automatically set at 125% of ideal)
$field->setTargetLength(100);

// Ideal length: 100 characters
// Minimum: 25
// Maximum: 150
$field->setTargetLength(100, 25, 150);

// Prefer to think in word count?
// 6 characters per word works okay for English
$field->setTargetLength(50*6);

Customise hint text

This module supports translation through yml, so if you want to change the hint text that is displayed when users are typing, just create your own language file to override the one included in the module.

Front-end use

If you want to use this module outside of the CMS, you will need to load a copy of jQuery and jQuery Entwine in to the page. Example:

Requirements::javascript('silverstripe/admin:thirdparty/jquery/jquery.js');
Requirements::javascript('silverstripe/admin:thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');

To Do

  • Translation
  • Customise hint text through config

Maintainer contact

Jono Menz

Sponsorship

If you want to boost morale of the maintainer you're welcome to make a small monthly donation through GitHub, or a one time donation through PayPal. ❤️ Thank you!

Please also feel free to get in touch if you want to hire the maintainer to develop a new feature, or discuss another opportunity.