Skip to Content Skip to Menu

Conditional Fields

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
3 years 9 months ago - 3 years 9 months ago #322215 by galanopd
Conditional Fields was created by galanopd
Hi,
I have searched the forum for related posts but I am still in doubt. I have the following fields: Region->Country->State->City.
Region field is visible. The rest appear conditionally if not empty, in the sequence shown above. I saw somewhere in the forum that the fields do not populate dynamically. I need to know how to implement the following:

QUESTION 1
1. FROM `#__comprofiler_countries` Region field to show ORDER BY `country_region` and `country_sub_region`.
2. Once the user selects a `country_sub_region` => the Country field appears showing the countries related to the specific `country_sub_region`.
3. Once the user selects one of the countries shown for the specific `country_sub_region` => the State field appears FROM `#__comprofiler_provinces` showing the States related to the specific `country_name`.
4. Once the user selects one of the States shown for the specific Country => the City field appears showing the Cities related to the specific `province_name`. (As for the 4th step, I will implement if/when I manage to find all the cities. An alternative to this could be for the user to input text in the field.)

The fields are shown/hide properly

QUESTION 2

Although the user might select North America->USA->Connecticut->Bridgeport, in case there is no member in the database from Bridgeport, I would like the system to show members from Connecticut.

Thank you
Last edit: 3 years 9 months ago by galanopd.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48425
  • Thanks: 8274
  • Karma: 1443
3 years 9 months ago #322224 by krileon
Replied by krileon on topic Conditional Fields

QUESTION 1
1. FROM `#__comprofiler_countries` Region field to show ORDER BY `country_region` and `country_sub_region`.
2. Once the user selects a `country_sub_region` => the Country field appears showing the countries related to the specific `country_sub_region`.
3. Once the user selects one of the countries shown for the specific `country_sub_region` => the State field appears FROM `#__comprofiler_provinces` showing the States related to the specific `country_name`.
4. Once the user selects one of the States shown for the specific Country => the City field appears showing the Cities related to the specific `province_name`. (As for the 4th step, I will implement if/when I manage to find all the cities. An alternative to this could be for the user to input text in the field.)

Use CB Query Field and build your select field from those database tables. Next be sure your query is dependent on the previous field. Now use CB Core Fields Ajax and configure the fields Update On to be for the previous field. This will for example cause Country to refresh when Region changes its value. An example of this using Query Autocomplete against text fields is included in CB Quickstart if CBSubs is installed.

Although the user might select North America->USA->Connecticut->Bridgeport, in case there is no member in the database from Bridgeport, I would like the system to show members from Connecticut.

Not sure what you mean by this. Usually best to show a text field for them to type their city if it's missing, which you can do by outputting a Other option then conditioning a text field to display.


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.

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
3 years 9 months ago - 3 years 9 months ago #322252 by galanopd
Replied by galanopd on topic Conditional Fields
Following your instructions, I've done most of it and it works fine, thank you.

Here is the issue I am facing:
I have 2 fields `cb_cat_bus` and `cb_subcat_bus` (depended on the former). I add the following query to get the table data

`cb_cat_bus` query works fine:
Code:
SELECT `name` FROM `#__professional_categ` WHERE parent=0 AND active=1 ORDER BY name ASC

`cb_subcat_bus` query doesn't:
Code:
$judgePick = $jinput->get('[cb_cat_bus]'); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select('x.name') ->from($db->quoteName('#__professional_categ', 'x')) ->join('LEFT', $db->quoteName('#__professional_categ', 'y') . ' ON ' . $db->quoteName('x.parent') .' = '. $db->quoteName('y.id')) ->where($db->quoteName('y.name') .' = '. $db->quote($judgePick)) ->andWhere(array($db->quoteName('x.parent').' = '. $db->quoteName('y.id'), $db->quoteName('x.active').' = 1'), $glue = 'AND') ->order($db->quoteName('x.name') . ' ASC'); $db->setQuery($query); $result = $db->loadColumn();
Last edit: 3 years 9 months ago by galanopd.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48425
  • Thanks: 8274
  • Karma: 1443
3 years 9 months ago #322272 by krileon
Replied by krileon on topic Conditional Fields

`cb_subcat_bus` query doesn't:

I assume that's a Code Select provided by CB Code Field. You don't need a Code Select for that. You can use a Query Select as follows.

Code:
SELECT x.`name` FROM `#__professional_categ` AS x LEFT JOIN `#__professional_categ` AS y ON x.`parent` = y.`id` WHERE y.`name` = '[cb_cat_bus]' AND x.`parent` = y.`id` AND x.`active` = 1 ORDER BY x.`name` ASC

Now this field would have Update On set to cb_cat_bus under Integrations > CB Core Fields Ajax. This will cause it to refresh its display when cb_cat_bus changes value. If you still want to use a Code Select then configure the Update On and make the following change.

FROM:
Code:
$judgePick = $jinput->get('[cb_cat_bus]');
TO:
Code:
$judgePick = '[cb_cat_bus]';


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.
The following user(s) said Thank You: galanopd

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

Moderators: beatnantkrileon
Powered by Kunena Forum