Skip to content

kristiandaugaard/silverstripe-text-target-length

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text Target Length for SilverStripe CMS

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 3.1+ (3.3 tested)

Installation

Composer (best practice)

Packagist listing and installation instructions

Manually

I promise it's worth your time to learn how to use Composer. If painless updating isn't your thing though you can download and extract this project, rename the module folder 'text-target-length', place it in your project root and run a dev/build?flush=1.

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);

Want to see more like this?

I donate a lot of my time to open-source projects, so if you use this module in a commercial project a small donation to keep me motivated would be much appreciated. If you'd like to sponsor additional development on this module I'd love to hear from you.

Donate

To Do

  • Translation
  • Customise hint text through config

Maintainer contact

jonathonmenz.com

About

Set character length recommendations on SilverStripe text form fields

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 47.4%
  • PHP 42.1%
  • CSS 10.5%