How to make a Field injected multiple times to the Form unique in ZF2?
Asked Answered
V

0

6

I have a pretty complex form with several nested Fieldsets and Collections. Some parts of the form are constant, other parts are variable:

BasicSettings EndpointBasicSource (constant part) EndpointBasicTarget (constant part) SpecificSettings EndpointType{TYPE}Source (variable part) EndpointType{TYPE}Target (variable part)

The EndpointBasicSource and EndpointBasicTarget contain a ServerFieldset, that provides the Field server_name. That means: The form contains at least 2 server_name Fields.

In the SpecificSettings depending on the EndpintType no, one, or both sides can contain a servers Collection (options.target_element.type => ServerFieldset) with up to 5 servers in it.

Here is a strongly simplified schema:

enter image description here

Now the servers should get unique (in all the server_name fields in the form a value may not recur). But how to do this? The problem is, that the ServerFieldset is injected via multiple other Fieldsets/Collections and the uniqueness validation needs to relate to the server_name Fields in all of them.

How can this problem be solved and a uniqueness validation for all the server_name in the entire form implemented?

Vookles answered 15/6, 2016 at 15:29 Comment(1)
Have you tried using a Callback validator? There you can get a specific input $value and the $context, which is an array with all the other inputs.Arliearliene

© 2022 - 2024 — McMap. All rights reserved.