-
Notifications
You must be signed in to change notification settings - Fork 89
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
Question: Is it possible to use a custom function for conditions within the schema in JSON format? #1418
Comments
Hi @bytecast-de this is not possible at the moment. I think we can come up with something similar to the action mapper though. I'll have to think about some reasonable format. Do you have some syntax in mind? |
Hi @Hyperkid123, thank you for your quick response. Based on the examples from the docs, there are some variations that come to mind from "user" perspective:
Variant 1 possibly won't work, as far as I've seen in the source, you can currently pass an array to "is", that behaves like "oneOf" - which is an undocumented feature, btw, or i missed it in the docs ;-) It maybe would be hard to make a distinction between the new feature and the old behaviour with arrays. Variant 2 is probably more work - i don't know how many other parts must be changed, to add another condition type. Variant 3 is in my opinion the most self-explaining and could possibly be used within the "is"-condition without the need to add another condition. Please let me know what you think about it, and if I can be of any help with this feature. |
@bytecast-de thanks for the suggestions. I was thinking about something similar, bit there is an issue. All of the examples of I think we will have to add some flag to the condition object that states that a particular condition is supposed to be mapped to a function
We can have an attribute like @rvsia opinion? |
Following attributes could be mapped to some function, nothing else makes sense in the condition context:
And we could use mappedAttributes (or similar name) to map them as we do with the actions:
|
@rvsia agreed. I hope I'll have some time later this week to implement the condition mapper. Feel free to pick the issue if you want. |
@Hyperkid123 @rvsia thanks for your feedback, sounds great to me - really looking forward to this feature. I'd like to add that this is an awesome project, much appreciated! |
OK I got some time on my hands. I'll work on the implementation |
@rvsia if we were to follow the current option for condition function config, it does not make sens to send anything other than the mapped attribute name. We do not pass any custom argument function conditions. Its always just a value and the condition config, |
Would it make sense to change it to higher-order-function to allow customization from the schema? 🤔 conditionMapper: {
ageValidation: (age = 18) => (value, config) => calculateAge(value, config) > (age)
}
// alcohol related page
schema = {
name: 'age',
component: 'date-picker',
condition: {
mappedAttributes: {
is: ['ageValidation', 18]
},
}
}
// senior sale related page :D
schema = {
name: 'age',
component: 'date-picker',
condition: {
mappedAttributes: {
is: ['ageValidation', 65]
},
}
} |
We can do that or append the arguments after the regular arguments. HOF will follow the pattern set within the validation mapper. |
@Hyperkid123 I would not append the arguments after regular - that could limit extensibility in the future. |
@rvsia I've added the HOC. Right now the mapped conditions will work only for the |
🎉 This issue has been resolved in version 3.22.0 🎉 The release is available on |
@bytecast-de You can check the docs here: https://www.data-driven-forms.org/mappers/condition-mapper |
@Hyperkid123 great job, thank you! |
Scope: react-form-renderer / conditions
Description
I am looking for a way to define a condition via custom function (https://www.data-driven-forms.org/schema/is#customfunction) BUT i cannot use a javascript object, the schema has to be in JSON format since it will be retrieved from the backend.
I've looked into the ActionMapper (https://www.data-driven-forms.org/mappers/action-mapper), but as far as I understand, the mapped functions can only be applied to a field property. In my case I would need to assign a mapped function inside a (possibly nested) condition - some sort of "ConditionMapper" if that makes any sense. See example below.
My question is: Can this somehow be done with the current implementation, or would this be a feature request?
Schema
This is the javascript version, works as documented:
This would be the corresponding JSON-Version, I have no idea if/how this can be done at the moment:
The text was updated successfully, but these errors were encountered: