Skip to Content Skip to Menu

🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

Selection of one group item to meet requirement

  • bizguy
  • bizguy
  • OFFLINE
  • Posts: 199
  • Thanks: 32
  • Karma: 5
1 year 2 months ago #335409 by bizguy
On a client website, there are a number of fields, all containing different items and the client would like to ensure that at least 1 item is selected from any field. I have grouped the fields together, and set the group to required, hoping this would be the result, but it seems Required has no effect in this Grouped field scenario.

Thoughts/suggestions?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
1 year 2 months ago #335415 by krileon
Field Group Fields can't be empty since there's always at least 1 row so marking them required doesn't really do much right now. You need to mark the fields in the field group as required.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • bizguy
  • bizguy
  • OFFLINE
  • Posts: 199
  • Thanks: 32
  • Karma: 5
1 year 2 months ago #335424 by bizguy
Thanks.
So to accomplish what the client wants, could an auto action check a number of fields to ensure at least one item has been selected before submission?
Then display a message about making a selection if none was made?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
1 year 2 months ago #335427 by krileon
Does this need to be a field group? You mention selection. Wouldn't a single multi-checkbox or multi-select fieldtype that's marked required accomplish this?


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • bizguy
  • bizguy
  • OFFLINE
  • Posts: 199
  • Thanks: 32
  • Karma: 5
1 year 2 months ago #335432 by bizguy
Unfortunately, there are 7-seperate fields with 10-30 items in each field to select from. The different fields are used to group similar items and allow searching within a field group.
examples:
Industry:
  • Accounting
  • Law
  • Dentistry
  • Education
  • etc
Functions
  • Creative
  • Administrator
  • Assistant
  • etc
So someone doesn't need to make a selection in each field, but the client wants them to select at least 1.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
1 year 2 months ago #335435 by krileon
You'll need custom validation rules to do that. The only thing I can think of is CB Code Field and its Code Validation functionality which lets you implement custom PHP based validation rules. The way it would work is when validating Field A you'd write the code to check if Field A OR Field B has a value and if it does then the field is valid. Example as follows.

Field A
Code Validation: Enable
Code (PHP):
Code:
return ( ( ( $value !== null ) && ( $value !== '' ) ) || ( $user->getString( 'FIELD_B_HERE', '' ) !== '' ) );
Ajax Validation: Enable
Additional Fields: FIELD_B_HERE

Replace FIELD_B_HERE with the name of whatever the second field is. You'd then select that same field in "Additional Fields" parameter for the client side validation behavior. Now just add more OR PHP cases and select additional fields as needed to add more fields to the validation check.

Now you'd edit Field B and do similar as follows.

Field B
Code Validation: Enable
Code (PHP):
Code:
return ( ( ( $value !== null ) && ( $value !== '' ) ) || ( $user->getString( 'FIELD_A_HERE', '' ) !== '' ) );
Ajax Validation: Enable
Additional Fields: FIELD_A_HERE

This should allow the fields and form to validate if Field A or Field B has a value.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum