How hard would it be to build a custom validation, that disables a selection when a maximum has been reached?
For instance, I have would like to organize a BBQ with 3 courses. Per course I have Hamburgers, Sausages, Steak, Corn and Chicken.

I would like to build build a registration form with the following rules:

  • Select one Item per course (single select option, easy)
  • Each course has to be unique, Eat with variation (Hurray for Webform validation)
  • Disable an item when the maximum number of items per course has been selected. I have 5 burgers per course, 8 pieces of corn etc.....

Any pointers?

CommentFileSizeAuthor
#6 Component.png96.59 KBAnonymous (not verified)
#6 Validation.png49.92 KBAnonymous (not verified)

Comments

liam morland’s picture

To have form controls disabled by JavaScript, you need to use Clientside Validation together with Webform Validation. If I understand your request correctly, Webform Validation can do the needed validation, but doesn't disable selections where there are too many. I don't know if Clientside Validation can do what you want or not. Give it a try. A patch to Clientside Validation might be needed.

Anonymous’s picture

As far as I figured out, webform Validation can' t solve the third requirement.

liam morland’s picture

Yes, that is the part that requires JavaScript. Webform Validation doesn't have any JS. That is all done in Clientside Validation.

Anonymous’s picture

I don't think that disabling an option will be the hard part (indeed client-side, or just remove the option from the component programatically) I think the hard part would be the server-side validation of the number of options chosen.
This would be a query using the count of cid, or can this be done using the webform api??

liam morland’s picture

You might have to write a custom validator. Webform Validation creates hooks that you can tie into from your own module so you only have to write a hook implementation declaring the validator and the validation logic.

Anonymous’s picture

StatusFileSize
new49.92 KB
new96.59 KB

Could you please pint me in the right direction?

I have added my rule, and I can choose from it in the "Form Validation" tab. Problem is I can only choose from the components, not from the options inside a component.

So I have a component "Course 1", with options:
Sausage
Corn
Chicken
Beef
Pork
Burger

How do I get those to show up in de validation form to enter the maximum oumount of total order for each ingredient per course??

Thanks in advance

liam morland’s picture

The configuration you can do through the UI is very limited. You will probably have to do your configuration in your code.

liam morland’s picture

Status: Active » Fixed

Please re-open if you need more help.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.