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.

Allow something other than the field "name" property to be the default when showing error messages.

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

By default, when an error message is displayed is uses "%s is required", where %s is the name of the field. The field name isn’t necessarily something to present to the user. For example, my field name might be parentId, but to the user I want to display Parent. In essence, across the entirety of my app I want to use the label as opposed to the name to display errors.

What does the proposed API look like?

I had a browse around the source, it seems as though fullField is an attempt to allow this, however it doesn’t appear to work correctly. See: https://codesandbox.io/s/v06vq5zlx0 which attempts to use fullField.

A potential API would be something like:

rules: [{
  required: true,
  errorProp: 'Parent'
}]

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
dengfupingcommented, Apr 8, 2018

@evantrimboli It’s unnecessary to supply such a feature. You could customize your error message using message property.

3reactions
evantrimbolicommented, Apr 8, 2018

Of course I could customize the label, but that’s not the point. It doesn’t scale for an app of any large size. There is no ability to have a convention based naming system.

For example, all the field names in my app are lower case. This means whenever an error is displayed, it will show as name is required. It would make more sense for it to read Name is required.

Now say I have 10 fields in a form. For each of those required field, I need to manually set the message because I want the required message to use Name and not name. This requires a bunch of repetition where it could be easily solved using a transform function.

Also consider I have a field with a min and max value length rule. That means I need to duplicate the text for both rules:

min: '%s must be at least %s characters',
max: '%s cannot be longer than %s characters',

Only because I want the label to be Product Price instead of product_price.

The framework should not just assume that the underlying programmatic name for a field should be something displayed to the user. Why do field labels exist? For this exact reason. The name for the error message should correspond with the label by default, because the label is shown to the user, not the name.

There should a way, either globally or potentially per rule some way to automatically transform the the field name before it is sent to the formatter.

The other thing you didn’t address is that it seems to already have an attempt to support this using fullField, but it’s not documented and doesn’t seem to work correctly. If it were intended to solely use the name property, why does it pass fullField to the validator in the first place?

I’d suggest you reconsider this, your answer doesn’t seem particularly deeply considered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I change or remove HTML5 form validation default ...
I think the idea with the title attribute is to describe the requirement like "Enter a 10-digit number." rather than an error like...
Read more >
Set default values for fields or controls - Microsoft Support
Right-click the control that you want to change, and then click Properties or press F4. Click the All tab in the property sheet,...
Read more >
PDF form field properties, Adobe Acrobat
This option is not available for form fields that do not display text. Note: The Enable Right-To-Left Language Options in the Language panel...
Read more >
Validation - Laravel - The PHP Framework For Web Artisans
Validating Nested Array Input; Error Message Indexes & Positions ... if the unique rule on the title attribute fails, the max rule will...
Read more >
Form and field validation - Django documentation
This method does not return anything and shouldn't alter the value. ... subclass – where <fieldname> is replaced with the name of the...
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