Buy Now
Sign in

how to get disabled validation on conditionnal field

flodariege , December 02 2018
F
flodariege 48
December 02 2018 #381955
Hello,
I am trying to get a checkboxes field being validated only if a specific option is selected inside another checkboxes group.
I tried many ways, but cannot get what I want. Maybe I don't do it the right way.
Here we go:
checkboxes 1 = choose one or several category
checkboxes 2 = choose one or several item inside the category chosen in checkboxes 1
This is the checkboxes_1 output in front:
checkboxes_1_front.JPG
When clicking an option, it opens a second (possibly a 3rd, 4th...) checkboxes, like this :
checkboxes_1_and_2_front.JPG
What I want, is preventing people not to make a choice inside the second list of options.
At this point, or I get validation while the 2nd list is hidden, or I don't get validation at all...
Let's have a look on backoffice :
Regarding the first checkboxes (category):
The validation tab (woking fine):
checkboxes_1_back_validation.JPG
and the events (hiding/showing works fine, but not the enable/disable validation):
checkboxes_1_back_events1.JPG
checkboxes_1_back_events2.JPG
Let's now have a look at the 2nd checkboxes, the one I don't want to validate if it is hidden and disabled.
First, the validation tab:
checkboxes_2_back_validation.JPG
And now the Info tab:
checkboxes_2_back_info.JPG
On the setup, I put a validate data action, but I think it is only checking for the consent checkbox prior the submit button (which validation works perfectly):
setup_validate.JPG
What am I doing wrong?
Even if I don't click the "chauffage" category, so the "solutions de chauffage" checkboxes stay hidden, CF6 validates it... and so it rejects the submit action.
I tried other settings, but then when the 2nd checkboxes are not hidden, and I don't chose nothing, the validation let it pass without saying nothing...
If only someone could tell me how to perform this... I've been trying for hours...
Thank you for your help
Flodariege
healyhatman 5.2
December 02 2018 #381961
You will need to either do the validation in PHP or have a series of event switcher actions. Data source for the switcher will be {data:checkbox1} or whatever, and in each of the options have a validate data action to validate only the fields that should be validated if that checkbox was ticked.
I would just do PHP validation in your case.
Also if they're not supposed to select an option, you should also disable it not just hide it.
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman

You can now copy+paste code from forums
F
flodariege 48
December 02 2018 #381963
Hi healyhatman,
Thank you for your response.
I don't feel confident about the php validation (I don't even know where to start), but I guess I could find a logical way to get through this with the Event switcher action. I had no idea what it was for.
And I won't forget to disable and hide, not only hide.
Thank you.
I will probably come back here with questions (or maybe to tell you I succeed )
healyhatman 5.2
December 02 2018 #381964
Sure thing.
Just remember in those events, the "disable validation" is ONLY for the jquery validation on the front end and doesn't affect the back end, otherwise users would be able to just edit the code on the front end and bypass all your server validation.
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman

You can now copy+paste code from forums
F
flodariege 48
December 07 2018 #382054
Hello healyhatman!
I'm sorry to bother you again, but I gave a try, and another, and another, and... but no way, I can't get how to set up the event switcher and validation correctly.
I also tried to find a good explanation inside the forum / faq / manual, with no success.
May I tell you what I did, so you could tell me what I did wrong and/or tell me what I am supposed to put as params?
Here we go:
On the design tab:
Checkboxes:
NAME: categorie_travaux

  • ID: categorie_travaux
    OPTIONS:
    chauffage=Chauffage
    pv=Photovoltaïque
    ecs=Chauffe-eau
    iso=Isolation thermique
    vmc=Ventilation (VMC)
  • VALIDATION:
    Required is ON
    Minimum choices: 1
    EVENTS:
    On Selecting chauffage => Enable + Show + Enable validation : solutions_chauffage
    On Unselecting chauffage => Disable + Hide + Disable validation : solutions_chauffage
  • Checkboxes:
    NAME: solutions_chauffage
    ID: solutions_chauffage
    OPTIONS:
    12344=Pompe à chaleur air-eau
    12023=Climatisation réversible
    12434=Chaudière à granulés
    (and so on)
    VALIDATION:
    Required is ON
    Minimum choices: 1
    Disabled is ON
    Error message: blablabla
    Validation rules : (nothing)
    LOAD STATES:
    Hidden: 1
    Disabled : (nothing)
    On the setup tab:
    On load:
    Display section
    On submit:
    Event switcher
    DATA PROVIDER: {data:categorie_travaux} (am I supposed to use the name or the ID? ie with or without the []?)
    EVENTS:
    chauffage,pv,ecs,iso,vmc (So I get 5 different events. let's have a look to the 1rst of them: )
    chauffage
    VALIDATE FIELDS
    List errors: Yes
    Data provider: {data:solutions_chauffage} (again, should I use the square brackets? name or ID?)
    Fields list selection: All fields with validation rules
    On success:
    (nothing)
    On fail:
    Event loader (with default values)
    Result: the 2nd checkboxes group show and hide, but if I don't tick anything in it while i selected chauffage in the 1rst checkboxes group, the form validates without any warning...
    There are so many different things I could have done wrong that I could spend a whole week trying to find the good combination...
    I feel almost desperate.
    Any little help would be very welcome.
    Thank you.
    Flo
    healyhatman 5.2
    December 07 2018 #382055
    Data source should be the "name" of the field.
    {data:fieldname}
    And you shouldn't use all fields with validation rules you should manually put in the rules that should be valid for the selections you've made. Unless of course all rules is valid for that selection.
    Web developer at SkySpider.com.au
    I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman

    You can now copy+paste code from forums
    F
    flodariege 48
    December 07 2018 #382057
    I must be stupid, I don't understand.
    I used the name = solutions_chauffage [ ] } (with no space but if I put it here with no space it turns into a dot)
    So:
    {data:solutions_chauffage [ ] } (no space)
    Fields list selection: Only the fields entered below
    solutions_chauffage
    ...doesn't work.
    You takled about putting the rules, but I don't understand where to put those rules (I see a 'fields' case, not any 'Rules' case).
    And it says : ""Multiline list of fields to be included or excluded based on the setting above.
    I also tried a VALIDATE DATA rather than a VALIDATE FIELDS, putting this validation rules inside the field 'on the Design tab):

    solutions_chauffage [ ] /minChecked[1]:Merci de sélectionner au moins une Solution
    ... with no more success.