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
[Form Validation] Add form validation rule: condition #988
base: develop
Are you sure you want to change the base?
Conversation
dc402cc
to
4159e1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please adjust . includes()
to make it work in ie11
Add the 'condition' validation rule. It allows form field values to be validated when another field is set to a certain value. Closes fomantic#985
4159e1f
to
47959e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🙂 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -1823,6 +1824,58 @@ $.fn.form.settings = { | |||
; | |||
}, | |||
|
|||
// applies rule if another field's value satisfies a condition | |||
condition: function(value, ancillary, $module) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a little difficulty to understand the new syntax...
My understanding is condition[FIELD_NAME, RULE1, RULE2, ... RULEn]
.
Am I on the right track?
If so, I feel it is a bit strange to treat FIELD_NAME
and RULE
s in the flat way.
I suggest a JSON-like syntax like { FIELD_NAME: [RULE], FIELD_NAME2: [RULE1, RULE2] }
.
This syntax distinguishes FIELD_NAME
and RULE
s.
This will also can cover use-case to have conditions on multiple fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, the current way will be too confusing for users and doesn't allow for expansion of the rule. I think your suggestion of making it JSON like will be our best shot to making it easy to use and easy to improve in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@exoego @hammy2899 Hello guys, based on what the author of this issue (#985) writes:
A built-in rule to validate a form field based on the value from another field of the same form.
I intended to lay out the parameters as follows, basically using the syntax proposed by the issue author:
condition[FIELD_NAME, VALUE_TO_CHECK_AGAINST, RULE_TO_APPLY]
which means: "if THAT_FIELD's value is VALUE, then apply RULE to this field".
Also I intended to set a hard limit on what RULE_TO_APPLY
can be, namely one single existing rule, on purpose. I was looking to not risk having recursive rules, or excessively complicated config.
With that said I'm absolutely open to improve this. If you think JSON-like syntax is the way to go, I'll change accordingly 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hammy2899 @exoego What are we going to do with this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think making this JSON like is still the best option we have especially for future support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hammy2899 please can you set out a small spec of how you envision this being JSON-like, then I'll try to take it from there. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a little difficulty to understand the new syntax...
My understanding is
condition[FIELD_NAME, RULE1, RULE2, ... RULEn]
.
Am I on the right track?
If so, I feel it is a bit strange to treatFIELD_NAME
andRULE
s in the flat way.I suggest a JSON-like syntax like
{ FIELD_NAME: [RULE], FIELD_NAME2: [RULE1, RULE2] }
.
This syntax distinguishesFIELD_NAME
andRULE
s.
This will also can cover use-case to have conditions on multiple fields.
Like how @exoego said
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vibridi Are you still interested in continuing to adjust the PR ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lubber-de I'm sorry, I don't think I will be able to work on this at this time. Feel free to close or take over. Thanks!
ed995fc
Description
This PR adds the
condition
validation rule. It allows to apply an arbitrary rule to a field value depending on another field value.Test Case
After: JSFiddle
Closes
#985