How to show only valid options in a select box?

Notice: This thread is very old.
MartyIX
Member | 217
+
0
-

Let's say I have a form where the first input is a select box with possible values (e.g. different fruits) and second select box containing possible colors. Now imagine that I have specified (via validation rules) combinations of fruit and its color that are valid.

Do you know about a simple method how to display only valid colors if a fruit is selected?

Note #1: I can use jQuery and write again almost the same rules to filter possible values as I did in form specification in PHP but I don't like the solution.

Note #2: This scenario is simplified you may have a more complex form with more complex rules. The idea is that if I have once specified the rules why to write them again in JS only to filter values.

How do you solve this problem?
Thanks!

Last edited by MartyIX (2012-03-12 13:09)

petr.pavel
Member | 535
+
0
-

I'm afraid Nette has no direct tool for that and I'm not aware of any add-on either.

Validation rules used with netteForms.js are stored in each form input's data-nette-rules. I guess you've noticed. You could take inspiration from netteForms.js and write your own parser/filter.

MartyIX
Member | 217
+
0
-

Yes, I'm aware where the validation rules are stored. I kind of hoped it won't be necessary. Thanks!