Skip to content
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

Field validation: Max characters #126

Closed
jossmac opened this issue Jan 17, 2014 · 11 comments

Comments

Projects
None yet
@jossmac
Copy link
Member

commented Jan 17, 2014

It'd be nice to be able to add { maxChars: x } to a field

@JedWatson

This comment has been minimized.

Copy link
Member

commented Jan 17, 2014

@bladey you just wrote a script for this, right? We could drop it into string(-like) fields, textareas, etc.

We could also specify an option that controls whether too-long should (a) show a warning in the UI (b) be cropped (c) throw a validation error.

@JedWatson

This comment has been minimized.

Copy link
Member

commented Jan 25, 2014

Could also be set to display the character count, even when no maximum is specified.

Should be set with an option on the field:

field: { type: String, max: x }
field: { type: String, max: { chars: x, mode: 'crop' } }
field: { type: String, displayChars: true }

mode would be one of

  • warn where the UI would show a warning if too many characters are entered, but not validate
  • crop where the field would crop values to the max chars before saving
  • validate where the field would not validate if too many characters are entered

I think crop should be the default behaviour if mode is not set, but am open to other suggestions.

If the displayChars option is set, the UI would just display the total number of characters entered into the field, without worrying about a maximum.

@albertogasparin

This comment has been minimized.

Copy link
Contributor

commented Apr 1, 2015

+1 👍
However I think that crop is bad UX. Cropping text without notice could lead to undesired strings.
I think the default behaviour should be validate (aka Twitter-like): the counter goes red, displays a -N and the item cannot be saved.
The alternative behaviour is warn, which makes the counter orange but nothing more.

@bradwbradw

This comment has been minimized.

Copy link

commented Jan 6, 2016

+1

@ericelliott

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2016

I think the default behaviour should be validate (aka Twitter-like): the counter goes red, displays a -N and the item cannot be saved.

👍

@bradwbradw

This comment has been minimized.

Copy link

commented Jan 7, 2016

@ericelliott agreed!

@mxstbr

This comment has been minimized.

Copy link
Member

commented Apr 29, 2016

We're closing all feature requests to keep the issue tracker unpolluted. I've moved this over, from now on submit feature requests on productpains.com!

@mxstbr mxstbr closed this Apr 29, 2016

@dariasamo dariasamo referenced this issue Jul 7, 2016

Merged

Max characters validation added #3131

1 of 1 task complete

@ostruzina ostruzina referenced this issue Jul 14, 2016

Merged

Added minimum character validation #3159

1 of 1 task complete
@shankarjois

This comment has been minimized.

Copy link

commented Nov 26, 2017

What is status of this?

@VinayaSathyanarayana

This comment has been minimized.

Copy link

commented Nov 27, 2017

is this not in latest beta?

@sheldon-sminq

This comment has been minimized.

Copy link

commented Dec 27, 2017

There is a bug in the beta version
current code

text.prototype.validateInput = function (data, callback) {
        var max = this.options.max;
        var min = this.options.min;
        var value = this.getValueFromData(data);
        var result = value === undefined || value === null || typeof value === 'string';
        if (max && typeof value === 'string') {
                result = value.length < max;
        }
        if (min && typeof value === 'string') {
                result = value.length > min;
        }
        utils.defer(callback, result);
};

With fix

text.prototype.validateInput = function (data, callback) {
        var max = this.options.max;
        var min = this.options.min;
        var value = this.getValueFromData(data);
        var result = value === undefined || value === null || typeof value === 'string';
        if (max && typeof value === 'string') {
                result = value.length < max;
        }
        if(result) {
           if (min && typeof value === 'string') {
                result = value.length > min;
           }
        }
        utils.defer(callback, result);
};
@tsuNammi

This comment has been minimized.

Copy link

commented Apr 11, 2018

Does this work for the WYSIWYG/tinymce too?

chasms added a commit to giantmachines/keystone that referenced this issue Jun 8, 2018

chasms added a commit to giantmachines/keystone that referenced this issue Aug 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.