Ensuring unique values in repeat group

Sophist

Guest
I am looking to ensure that a field in the repeat group is unique for that parent record.

isuniquevalue / areuniquevalues don't do it - and probably shouldn't be expected to because they are intended to work where there is only a single database row to worry about and repeat groups use multiple rows.

So a few questions around this area:

1. Is there a validation plugin (server side php) that will perform this?

2. Is there any easy way of doing client-side JS validation of this also?

3. Is there any way of disabling options of other dropdowns that match the selected option of this dropdown in order that the user cannot select that value?

Thanks.
 
1) No, there isn't a built in validation for this, although it wouldn't be too tough to do with a PHP validation.

2) & 3) I have done exactly this before in Javascript, and it's on the forums somewhere, but it was quite a long time ago and I can't remember enough specific about the post to find it. My Google Fu is weak today.

But yes. Click events on the dropdowns, which disable the selected value on all the other copies of the dropdown. And the advantage of doing it that way is you don't have to worry about server side validation - if you do the JS right, it's not possible to submit duplicate values.

It's something that has come up often enough that I have thought about building a canned solution for it, but finding where to put that is the problem. I'd probably have to extend the validation model to support JS methods.

-- hugh
 
After I also decided that a pure PHP solution is tough (because you cannot test it with Ajax server calls - combinations of rows already saved and not yet saved). However I managed it using pure JS events - and I have created a Wiki entry for it because my code is generic.

But it was only achievable after I added a missing unload event when you delete a row. (Part of https://github.com/Fabrik/fabrik/pull/1939 which fixes several repeat group related issues).

It would be nice if you could have a pre-canned solution, but there are no such things as JS plugins (at least not yet). And if we are doing so blue-sky wishful thinking, making validation plugins hybrid so that they automatically work using JS before submit and (for anti-spoofing) using php during submit. But when validation plugins contain bespoke php then user would also need to write matching JS - or you can take a couple of years (or decades) off and create a perfect-in-all-circumstances php->js translator. ;-)
 
@dimoss - thanks. It seems to me that using this code as a basis it might be possible to code a validation plugin for this, or instead to code a form plugin. But you could also incorporate this code in a Form php plugin I would imagine.

At the moment I am happy with the JS solution I have documented - because I am not overly worried about doing a server-side check, but it would be useful to have something in the kit-bag.
 
As Hugh said before, I have seen the same or nearly the same question often so the best would be to have a pre-set solution if possible.
Repeating groups are always "pain" to validate!
 
@startpoint - thanks, I forgot I added that one to the wiki. Although that code is somewhat simpler, as it involves separate elements, not repeats of the same one. And I know somewhere in the forums I did that for someone. I really should have added it to the wiki when I posted it.

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

Thank you.

Members online

No members online now.
Back
Top