• REGISTRATION REQUIREMENTS:

    Your username here MUST MATCH your XenForo username (connected to your XF license).

    Once you have registered here, then you need to start a conversation at xenforo.com w/Bob and provide the following:
    1. Your XenForo License Validation Token
    2. The Domain Name associated with the License
    NOTE: Your account will be validated once ALL requirements are verified/met. Thank you for your patience.

Custom Field Second Dropdown Based On Previous Dropdown's Selection

Artemis Obauldi

New Member
AMS
Showcase
I'm very new at this.

1. I'm using showcase for an RPG and would like to display "Races" and "Sub-Races" dropdown menus via Custom Fields when creating an item.

2. I would like the options of Sub-Races to change dynamically and be based upon the selection of the previous dropdown menu, Races.

3. I would like to do this via this jquery snippet I found (unless there's a better/easier way), and am wondering how I might go about using it to my advantage.

$(document).ready(function() {
$('#Rank').bind('change', function() {
var elements = $('div.container').children().hide(); // hide all the elements
var value = $(this).val();

if (value.length) { // if somethings' selected
elements.filter('.' + value).show(); // show the ones we want
}
}).trigger('change');
});

Demo Link: http://jsfiddle.net/3UWk2/1/
Stackexchange Discussion: http://stackoverflow.com/questions/...dropdown-based-on-previous-dropdown-selection

I'm assuming the Showcase Custom Field Dropdown Menu would be replacing the HTML the dude in the Stackexchange Discussion is using, so I'd be using values like $fieldID. I'm also curious what $value I'd use for the Options of the Dropdown Menus, like what's the correct syntax for fetching it.

Any help would be mucho appreciated!
 
That is not possible with how custom fields work. To do what you want to do would require custom development outside of custom fields (or MAJOR modification to the entire custom fields functionality). IMO, you'd be better off staying away from custom fields and extending the addon itself (much less work IMO). Either way tho requires a pretty good understanding of php/mysql & xenforo's MVC framework.
 
Here is my workaround for a dynamic drop down based on a previous drop down selection

Install this addon
https://xenforo.com/community/resources/multiple-choice-fields-by-waindigo.3825/

Run the following SQL in phpMyAdmin to add a new field called multiple_choice_waindigo to the xf_nflj_showcase_custom_field

Code:
ALTER TABLE  `xf_nflj_showcase_custom_field` ADD  `multiple_choice_waindigo` TINYINT UNSIGNED NOT NULL DEFAULT  '0'

Create a new showcase drop down custom field

1.jpg

Create the drop down choices for the first and second drop down by separating the entries by a pipe "|".

In this example, the first drop down contains the companies Honda, BMW and Chevrolet. The second drop down will then be dynamically generated based on the company selected and will display the respective models from the selected company.
So if BMW is selected, the second drop down will contain M3, M4 and M5.

2.jpg

Go back to phpMyAdmin and set the multiple_choice_waindigo field in the xf_nflj_showcase_custom_field to 1

Code:
UPDATE  `showcase`.`xf_nflj_showcase_custom_field` SET  `multiple_choice_waindigo` =  '1' WHERE  `xf_nflj_showcase_custom_field`.`field_id` =  'vehicle';

upload_2015-6-13_16-17-51.png

When creating a new showcase only the first drop down is initially shown

upload_2015-6-13_16-18-44.png
Company selection

upload_2015-6-13_16-20-11.png

Once the company is selected, the models show up
upload_2015-6-13_16-21-5.png
Model has been selected

upload_2015-6-13_16-21-54.png
Submitted showcase item

The vehicle shows up as BMW|M5. See next post on how to remove the "|".

upload_2015-6-13_16-23-6.png
 
Last edited:
The "|" separating the make and model can be removed with a template callback

In the library folder create a new folder called Custom

Create a new empty file called Showcase.php

upload_2015-6-13_17-30-37.png

Add the following code, which will replace the "|" with a space, to the Showcase.php file

Code:
<?php

class Custom_Showcase
{
    public static function renderVehicle()
    {
        $val = func_get_arg(1);
        return  str_replace("|"," ", $val);
    }
}

?>

Change the display location of the vehicle custom field to Self Placement
3.jpg

Edit the nflj_showcase_item_field_group template and add the following before the </xen:contentcheck> tag

Code:
<xen:if is="{$item.customFields.vehicle}">
    <div class="customShowcaseFields tab1">
        <dl class="customShowcaseFieldvehicle">
            <dt>Vehicle:</dt>
            <dd><xen:callback class="Custom_Showcase" method="renderVehicle"   params="{xen:helper showcaseFieldValue, $item, 'vehicle', {$item.customFields.vehicle}}"></xen:callback></dd>
        </dl>
    </div>
</xen:if>
upload_2015-6-13_17-34-26.png

End result
upload_2015-6-13_17-38-18.png
 
Back
Top