Ryan Tate | 4 Mar 02:21

[FormBuilder] requiring any of several fields

As far as I can tell, there is no way to require that any one of
several fields be present.

I have an app where I need either field1 or field2 filled out. Neither
on its own is required, and a validate method attached to either field
would not detect when both are empty because it would never get
called!

The workaround for me is to inspect the form after it is submitted,
andmake sure one of the fields is set. If not, I mark one field as
invalid and set its message to something useful, then send the form
back to the user.

What would be more useful would be a formwide_validate callback that
checks the whole form, as opposed to a particular field like normal
validate. This would be the logical place to do what I'm trying to
accomplish.

$form->formwide_validate(sub{
  my $form = shift;
  ($form->field('foo') || $form->field('bar')) or return;
  return 1;
});
_______________________________________________
FBusers mailing list
FBusers <at> formbuilder.org
http://www.formbuilder.org/mailman/listinfo/fbusers


Gmane