Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » Dynamic Filtered Drop-Down Choice Fields

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

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

Page: 1
Go to End
Author Topic: 1890 Views
  • Webdoc
    Avatar
    Community Member
    332 Posts

    Dynamic Filtered Drop-Down Choice Fields Link to this post

    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

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Dynamic Filtered Drop-Down Choice Fields Link to this post

    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.

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Dynamic Filtered Drop-Down Choice Fields Link to this post

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

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Dynamic Filtered Drop-Down Choice Fields Link to this post

    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.

  • pedro2555
    Avatar
    Community Member
    2 Posts

    Re: Dynamic Filtered Drop-Down Choice Fields Link to this post

    Try out the FilteredDropdownSet from DataObjectManager.

    1890 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.