bpmn-io / form-js

View and visually edit JSON-based forms.
https://bpmn.io/toolkit/form-js/
Other
405 stars 103 forks source link

Support programming validator #499

Open vanpipy opened 1 year ago

vanpipy commented 1 year ago

Is your feature request related to a problem? Please describe

Nope

Describe the solution you'd like

Just like the implement of the Validator, i want one more property like schema.components[0].validate.executor to try a customized validation. But i cannot found any design for that or any place to extend it without changing the original code, so here is the feature request and thanks.

Describe alternatives you've considered

Nope

Additional context

No one

vanpipy commented 1 year ago

Is useless to use the custom validator in the reality playground?

pinussilvestrus commented 1 year ago

Hi @vanpipy, thanks for your request.

You are right that there is currently the option to provide a custom validation regex pattern:

Image

What would you envision on top exactly? What should that executor property look like? A possibility to provide custom functions, e.g. Javascript, or something else?

vanpipy commented 1 year ago

Hi @vanpipy, thanks for your request.

You are right that there is currently the option to provide a custom validation regex pattern:

Image

What would you envision on top exactly? What should that executor property look like? A possibility to provide custom functions, e.g. Javascript, or something else?

Thanks your response.

The Regular expression pattern is the https://github.com/bpmn-io/form-js/blob/811af4de535a9402cd54eeeaefde6bea4f2e9fb0/packages/form-js-viewer/src/core/Validator.js#L65

And yes, a custom function is i wanted. I speed some time to think to reach the goal via the custom function and found the changing scope is not small cause everything in the validator should be a executor and the executor generates the validation result always. That makes sense when adding the executor property.

Then the executor cannot be used in the playground, it means the feature executor is just for the dev user. So it is usefull? Or useless?

pinussilvestrus commented 1 year ago

Then the executor cannot be used in the playground, it means the feature executor is just for the dev user. So it is usefull? Or useless?

I wouldn't say it's impossible to test it in some way in the forms playground, there are ways to deliver this (e.g. via another window to simulate JS functions in the browser in a safe sandbox manner). Also, you'd able to test this in the preview panel, at least visually.

The more interesting question would be whether this is a route we'd want to go from a library perspective. We currently use FEEL as our go-to scripting (expression) language. /cc @christian-konrad

I'm moving this to backlog until we didn't decide on that.

vanpipy commented 1 year ago

The more interesting question would be whether this is a route we'd want to go from a library perspective.

I get your idea and understand a litte about the why. Follow the FEEL language, current implement is great.

In the playground, there are some expressions, like the min, max or pattern, so there are some functions as below:

Follow the rule above, the executor is hard to define with the FEEL.


this is the way i think:

expressions: min, max, regexp etc.
function: expression + expression

user types expressions -> composite the expression as a function -> execute the function to get validation result

Hope it useful and I am looking forward the changes.

Thanks a lots.

pinussilvestrus commented 1 year ago

Thanks for your thoughts @vanpipy 👍