Code

1 year 3 months ago #332411 by bmeeker
Code was created by bmeeker
I can't find documentation on the Code Drop Down (Multi-Select) field.
I have the following in the code section, but get an error message no matter how I try to configure.
array( '03' => array( '03' => 'Dental' ))
Producing error:
syntax error, unexpected token "}"

My goal is to be able to create an option that uses the name in another cb field to populate. The field is the name of the page.
The option label (Dental) would be the name of the page and the value would be, in this case 3.
I would like to replace the page name (Dental) with the user's cb field value for the page, either using CB code if possible, or do a mySQL query to get the name (Dental) from the field.
I tried: array( '03' => '[cb:userdata field="cb_menulabeldental" user="#displayed" /]' ) but that gave same error.

Also tried [cb:userdata field="cb_menulabeldental" user="#displayed" /] as Label in standard multi-select dropdown and it didn't work

As always - thank for your help.

Please Log in to join the conversation.

1 year 3 months ago #332414 by bmeeker
Replied by bmeeker on topic Code
I was able to get it to somewhat work, but I'm confused as to why first values (03, 04, 05) are shown as the drop down labels when choosing, but the userdata fields show in the list of selected fields once submitted.
I tried to use the cb field instead of 03, but it wouldn't allow it.
Here is what I have so far - for 3 of many pages:

$test1 = array( '03' => '[cb:userdata field="cb_menulabelmedical" user="#displayed" /]', '04' => '[cb:userdata field="cb_menulabeldental" user="#displayed" /]', '05' => '[cb:userdata field="cb_menulabelvision" user="#displayed" /]' );
return $test1;

Thanks again.

Please Log in to join the conversation.

1 year 3 months ago - 1 year 3 months ago #332425 by krileon
Replied by krileon on topic Code
CB Code Field and its Code Select just requires valid PHP. If you're getting a syntax error then your PHP isn't valid. It expects an array return as described in the parameters description. Example as follows.

return [ 'value_1' => 'Value 1', 'value_2' => 'Value 2', 'value_3' => 'Value 3' ];


To have grouped options you can supply a nested array as follows.

return [ 'Group 1' => [ 'group_value_1' => 'Value 1', 'group_value_2' => 'Value 2', 'group_value_3' => 'Value 3' ], 'value_2' => 'Value 2', 'value_3' => 'Value 3' ];


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 to join the conversation.

1 year 3 months ago #332430 by bmeeker
Replied by bmeeker on topic Code
Sorry Kyle - I do not follow.
The drop down shows the values 3,4 and 5 in the list. When selected and saved, the database show 3|*|4|*|5 - which is correct.
Also when selected and saved, the field shows the labels (Medical, Dental, Vision) - which is correct.

But I want the labels to be shown in the dropdown instead of the value.
When the field is saved it should still show the labels (Medical, Dental, Vision), and the values to be stored in the database (3|*|4|*|5).
Here is what I have, trying to use your response.

return [ '3' => '[cb:userdata field="cb_menulabelmedical" user="#displayed" /]', '4' => '[cb:userdata field="cb_menulabeldental" user="#displayed" /]', '5' => '[cb:userdata field="cb_menulabelvision" user="#displayed" /]' ];

Any help getting this formatted correctly would be greatly appreciated.

Please Log in to join the conversation.

1 year 3 months ago #332443 by krileon
Replied by krileon on topic Code
Sorry, misunderstood what you were asking! You're using userdata substitutions. That's the same as [FIELD_VALUE] and will output the raw stored value. If you need formatted values be sure to use userfield substitutions. See substitution below for further explanation and examples.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18353-using-substitutions-throughout-cb

So you should be able to just make the following adjustment for example.

FROM: [cb:userdata field="cb_menulabelmedical" user="#displayed" /]
TO: [cb:userfield field="cb_menulabelmedical" user="#displayed" /]

I'm not entirely sure why you're using another field as the label though? Ideally those should probably just be language strings.


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 to join the conversation.

1 year 3 months ago #332446 by bmeeker
Replied by bmeeker on topic Code
Kyle:
I have attached a PDF with screenshots and maybe a better explanation of what I I am trying to accomplish, and why.
Sorry about any confusion, I should have included images to help in understanding from the start.

Again, as always - thank you for your time and your help. It has assisted me in creating a pretty kick-ass site.
Attachments:

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.232 seconds