Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Dynamic Filtered Drop-Down Choice Fields


Go to End


5 Posts   2713 Views

Avatar
Webdoc

Community Member, 349 Posts

30 December 2009 at 5:02am

Have tried to make the form with user forms and script search.js jusing code:

Search.js

<script type="text/javascript" charset="utf-8">
            function FilterModels() {
                var makeslist = document.getElementById('makes');
                var modelslist = document.getElementById('models');
                var make_id = makeslist.options[makeslist.selectedIndex].value;
                var modelstxt = new Array();
                modelstxt[1] = "1\tEscort\n2\tTaurus";
                modelstxt[2] = "1\tAltima\n2\tMaxima";
                var models = modelstxt[make_id].split("\n");
                for (var count = modelslist.options.length-1; count >-1; count--){
                    modelslist.options[count] = null;
                }
                for (i=0; i<models.length; i++){
                    var modelvals = models.split("\t");
                    var option = new Option(modelvals[1], modelvals[2], false, false);
                    modelslist.options[modelslist.length] = option;
                }
            }
        </script>

For the userforms i used html block for manufacturer with code:

<select name="makes" onchange="FilterModels()" id="makes">
                <option>--</option>
                <option value="1">Ford</option>
                <option value="2">Nissan</option>
            </select> 

and for html bloxk model this code:

<select name="models" id="models">
                <option>Choose Make</option>
            </select> 

But when i submit the query it gives blank fields how i can fix it.

the tutorial can be fond here:

http://www.nerdydork.com/dynamic-filtered-drop-down-choice-fields-with-django.html

Avatar
Webdoc

Community Member, 349 Posts

30 December 2009 at 9:08am

Or is there a possible way to make it like Simple ContactPage with dropdowns that have value. in userforms when u use the dropdownfield it only have role option name .but no name and value.

Avatar
Webdoc

Community Member, 349 Posts

30 December 2009 at 9:13am

As i understand i need to write somewhere code that posts the selected field but how to do it i dont understand.

Avatar
zenmonkey

Community Member, 545 Posts

1 January 2010 at 5:53am

Well if you just want to fully populate all the drop downs and then filter them you could always jQuery the whole thing to do reveal the various drop down and options. Otherwise you'll have to create a custom form functions in your page controller that populates the first list and on select refreshes the page and populates the next next list. (There's a multi page form tutorial somewhere) Personally I find the jQuery option easier but you'll lose fallback for people that don't have Javascript enabled.

Avatar
pedro2555

Community Member, 2 Posts

3 May 2012 at 11:47pm

Try out the FilteredDropdownSet from DataObjectManager.