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

Add support of typeField property validation message #4450

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

GogoVega
Copy link
Contributor

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

This PR is an extension of #4449 and was discussed inside.

If an input is builded with typedInput and contains the typeField option:

$("#node-input-path").typedInput({
    default: "str",
    typeField: "#node-input-pathType",
    types: ["str", "msg"],
});

and node properties contains a validator for typeField:

defaults: {
    path: {
        value: "",
        ...
    },
    pathType: {
        value: "str",
        validate: RED.validators.regex(/^str$/),
        ...
    }, ...
}

This PR adds a validation tooltip message to the field if the typeField validation is not correct.

In the example, validation only accepts the type str not msg:
Capture d’écran 2023-11-27 à 11 27 14

Note: the message on the screenshot is not the message that the example should produce

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run npm run test to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@knolleary knolleary added this to the 4.0 milestone Jan 19, 2024
@knolleary
Copy link
Member

Whilst this works for 'top level' properties, it doesn't automatically apply to general usage of TypedInput. For example, in a switch node, I get the tooltop in the top TypedInput, but not one embedded inside the rules property.

The typedInput already does validation on itself, so this feature may be better served by adding it to TypedInput itself. This would lose the ability to do custom validation on the Type field, but I'm not sure how common a use case that is compared to better feedback on general TypedInput errors.

image

@GogoVega
Copy link
Contributor Author

I'm going to check that 🤔

@GogoVega
Copy link
Contributor Author

So... yes, I also worked on the non "top-level" part here but I haven't created a PR yet.

PS: To see if we keep the "prettier" modifications?

PPS: I believe there remains this question. I will check the content for this weekend 😉

@GogoVega
Copy link
Contributor Author

GogoVega commented Jun 2, 2024

Regarding your second question, typedInput has an internal validator but it is not directly linked to node validation.

If typedInput uses its default validators, only a custom validation (Regex rules for example) in the node will add an error to the field. In the other case, the node validation will retrieve the result from typedInput.

I grant you that we do the job twice for the "top" elements but these elements can be defined differently - the "safest" behavior (in the sense of validating the node) being to validate it on both sides.

@GogoVega
Copy link
Contributor Author

GogoVega commented Jun 2, 2024

Ok, I added a rule that lets validate by typedInput if there is no node validation for the property.

GogoVega added a commit to GogoVega/node-red that referenced this pull request Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants