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

DX Custom Rule #234

Open
DerickO-Nedbank opened this issue Mar 3, 2021 · 3 comments
Open

DX Custom Rule #234

DerickO-Nedbank opened this issue Mar 3, 2021 · 3 comments

Comments

@DerickO-Nedbank
Copy link

Hi guys,

I'm writing a Vue app with a form containing 3 fields (ID, Profile, Account). All 3 are number fields.

I need to write a validation rule that checks that at least one of the 3 is populated.

From what I understood - I could do this with a custom rule.

I have 2 questions:

  1. Is there a way to debug dx expressions? I'm happy to figure them out - but find it hard without being able to see them evaluate.
  2. My idea was to use a rule like the example below on each of the 3 fields and to tell each one to fire the other 2 rules, so that they all update at roughly the same time.

Can you please see if I'm on the right track? I've tried various expressions, but I can't seem to hit the right one and I also don't see the two other rules fire when the first one evaluates....

This is the rule on the "id" field:

"rules":{
"customRule": [{
"script": "dx: !{{$root.Victim.identityNumber}} && !{{$root.Victim.profileNumber}} && !{{$root.Victim.accountNumber}} ",
"errMsg": "You need to specify at least one of the following: an ID Number or Profile number or Account number",
"linkItems": [
{
"fieldPath": "profileNumber",
"customRuleIdx": 0
},
{
"fieldPath": "accountNumber",
"customRuleIdx": 0
}
]
}]
}

Many thanks,
D

@daniel-dx
Copy link
Collaborator

daniel-dx commented Mar 4, 2021

  1. Q:Is there a way to debug dx expressions? I'm happy to figure them out - but find it hard without being able to see them evaluate.
    A: You can use function style of dx to debug the value, refer to https://github.com/ncform/ncform#dx-expression

  2. Q: My idea was to use a rule like the example below on each of the 3 fields and to tell each one to fire the other 2 rules, so that they all update at roughly the same time.
    A: Refer to this example: https://codepen.io/daniel-dx/pen/eYBKXVL. But there has some problems:

    1. you must hide the "*" symbol by yourself (may be by overriding the style)
    2. there is a bug that when the required message show and the filed's rule become no required, the required message cannot hide automatically(this i will fix it as soon as possble)

@DerickO-Nedbank
Copy link
Author

Thanks Daniel!

I totally missed the note about function-style dx expressions - that's really brilliant. Does this mean that the dx-syntax is just there to enable a shorter form for writing very simple expressions or is there a performance penalty in choosing one style over the other? I would imagine the dx-expressions must be slightly slower - since they need to be parsed/processed? (probably not even measurable for most common situations).

I'll leave this issue open until the bug is fixed. If you have another issue tracking the bug - please feel free to close this one.

@daniel-dx
Copy link
Collaborator

If you want to pass the schema to server, you can only use the string-style dx.
And if you just write the schema in the code, you can feel free to use the function-style

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

No branches or pull requests

2 participants