Repository navigation
Conversation
knolleary
left a comment
There was a problem hiding this comment.
Thanks for this.
It would have been easier to review if it did not also update all core nodes to use this new API. Because now any feedback/changes on the API has to be made across all of the nodes.
In the proposal, you have added a label property to the property definition:
// example:
defaults: {
property_name: {
value: ..., required: true, label: "meaningful name"
}, ...
}
Separately, you have updated the built-in validators to take an object that also lets you provide a meaningful name:
defaults: {
property_name: {
value: ...,
validate: RED.validators.number(false, {
property: "meaningful property name"
})
}, ...
}
That feels like duplication. As the editor will be calling the validator for a particular property, can it not provide the property information itself and remove the need for the user to duplicate it?
| valid = definition[property].validate.call(node,value, opt); | ||
| if ((typeof valid) === "string") { | ||
| return valid; | ||
| } |
There was a problem hiding this comment.
It is possible that an existing validate function returns a String and relies on "" being false and anything else being true.
This code would then cause it to incorrectly mark the property as invalid. We discussed in the forum using the new second argument as a sign the validate function returns strings to mean invalid.
| valid = definition[property].validate.call(node,value, opt); | |
| if ((typeof valid) === "string") { | |
| return valid; | |
| } | |
| valid = definition[property].validate.call(node,value, opt); | |
| // If the validator takes two arguments, it is a 3.x validator that | |
| // can return a String to mean 'invalid' and provide a reason | |
| if (definition[property].validate.length === 2 && (typeof valid) === "string") { | |
| return valid; | |
| } |
There was a problem hiding this comment.
Sorry for late reply.
I have merged your suggested code.
Regarding the built-in validator, I have changed it to use the label property of property definition.
|
Are these "meaningful labels" easily translated ? by the standard |
Yes. You can define it in property definition as: |
Proposed changes
As discussed in this forum thread, the purpose of this PR is to present to the user the cause of the failure of node property verification in an easy-to-understand manner.
For compatibility, this function takes optional second argument which is currently empty object. So, newly developed node can check this argument and change its behavior.
labelproperty. The value s used as a display name in the validation of the required field and configuration node error.RED.validators.*is modified to accept additional option object. This object can have apropertyproperty. property The property is used as the display name when generating an error message.deletefunction toRED.popover.tooltip.typedInput), probably because of a conflict.Checklist
gruntto verify the unit tests pass