how to prevent two field equal in two repeated group?

samani

Member
i have a form that has for example 5 repeated group and i want to not allowed to user to save two group with equal value of field A of each group?
how to validate that? is "isuniqueValidation" good for my goal or must use PHP validation?
 
I think you'd have to do it with the PHP validation. The isunique validation will only test "this" instance against the existing values in the database, not against other repeated instances in the same submission.

Something like ...

Code:
foreach ($formModel->formData['yourtable___yourelement'] as $key => $value) {
   if ($data == $value && $key != $repeatCounter) {
      return false;
   }
}

Depending what element type it is, you may need to do a little more processing.

I just tested that code with a simple field element and it works. For a join (rendered as a dropdown) it would need to be:


Code:
foreach ($formModel->formData['yourtable___yourelement'] as $key => $value) {
   if ($data == $value[0] && $key != $repeatCounter) {
      return false;
   }
}

... as $value will be an array.

-- hugh
 
We are in need of some funding.
More details.

Thank you.
Back
Top