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:
- Created 5 years ago
- Reactions:4
- Comments:12 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@evantrimboli It’s unnecessary to supply such a feature. You could customize your error message using
message
property.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 readName 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 notname
. 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:
Only because I want the label to be
Product Price
instead ofproduct_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 passfullField
to the validator in the first place?I’d suggest you reconsider this, your answer doesn’t seem particularly deeply considered.