I have a form of roughly a dozen catering entrees (single product fields, quantity enabled). On this particular form, it is desired to limit total portions. I’m using a number field with calculation enabled, adding up the quantities.
I’d like a limit validation on this number field but I’m not familiar with the code enough to pull it off. Hoping someone here can point me in the right direction.
I’d like the validation to allow total portions less than or equal to X.
I write it this way because if the future number of allowed portions changes, I’d like to be able to go in and adjust that one number. If in practice it’s easier to define the failure, I’m fine with it being greater than or equal to X, knowing X must be 1 greater than the allowed quantity.
Any help pulling this together would be appreciated.
I think I have found a solution. I was misunderstanding the trigger and timing of everything.
Originally when I added my own modified number field validation (example 1 from https://docs.gravityforms.com/gform_field_validation/), it didn’t seem to work and I thought I had the code wrong. In fact, I had an inaccurate expectation of instant gratification. Not sure why, but for whatever reason my brain latched onto the validation ought to be showing immediately. Of course it only shows when the form submission is attempted.
So because instant gratification was still desired for usability, here is what I did.
I added an HTML field with my own notice text to appear conditionally when the value of my number field exceeded the desired quantity ‘X’. So now instantly the user is shown a dialog ‘hey you’re over the allowed quantity’ and then if/when they ignore the dialog and try submitting, the validation prevents it.
I think this will work.
That sounds like a perfectly acceptable solution. Is that working for you?