Form::IS_IN custom implementation

Notice: This thread is very old.
Matúš Matula
Member | 257
+
0
-

question asked here https://github.com/…ms/issues/21

I mean is'nt it useful in your opinion to have that rule e.g. for MultiSelecBox?
Let's have this example:
we have a users admin interface where every user can have multiple user roles. To each role some other conditions (mandatory fields) specific to role may apply. In this case we need to toggle(or validate) those conditions if that role is being selected. And obviously not just in case it's the only role selected but if it's one of many.

does it make any sense to you now?

Jan Endel
Member | 1016
+
0
-

You can implement your own validation and put it here like a callback.

Matúš Matula
Member | 257
+
0
-

I know I can. I already did. I am just curious why it's not already embedded

Edit: I mean, why IS_IN is mapped to EQUAL. But maybe the behaviour I want is not suitable for IS_IN rule and rather new rule should be created for this. related pull

Last edited by Matúš Matula (2014-05-28 17:43)

duke
Member | 650
+
0
-

I guess the reason why the IS_IN and EQUAL rules are implemented as EQUAL being alias for the IS_IN is because EQUAL is actually a special case of IS_IN (it is IS_IN with a single argument). Core question is what is checked by the rule, because apparently in case of multiselect, it is not the value as a whole (which can be a vector), but rather its every component (multitude of scalars). You seem to want to apply EQUAL rule on whole value though. That is however not supported unless I missed something (but it could be emulated using complex conditions working with the scalars).

To be honest I wasn't sure myself how IS_IN rule for multiselect works in Nette (couldn't find it described anywhere neither in documentation nor on forum), until I tried it.