2

I have a list I am building that has one column (A)(Divisions) with 8 choices and another column (B)(Branches) that has 42 choices. Is it possible to set it so that the choices in column (B) are limited to just a few choices based on what is selected in column (A)? Unfortunately I am limited in what I can apply to the list so I have to stay to the out of the box solutions using the list settings for any formatting. Any help with a formula and instructions would be a huge help.

Thank you.

7
  • Can't do it OOTB. Can you add javascript? It's client-side and doesn't require elevated permissions? – Erin L Mar 28 '16 at 16:52
  • Not without going through a major pain. Its an enterprise system and I am even lucky that I can build lists/libraries. – Taiter Mar 28 '16 at 16:54
  • I just logged in as my test user who has Manage Lists and Contribute permissions. Then I went into List Settings > Advanced > Launch forms in a dialog? = No. Then I added a new item, and on the new item form, Site Actions >> Edit Page. If you are able to do this, you can add javascript to the page. – Erin L Mar 28 '16 at 17:01
  • Thanks Erin. That was all greek to me. I can edit pages but am limited on what webparts I can add. I am also not at all familiar with programing Java script. Its really no big deal to me that people will have to scroll through a long list to find their right branch, but I am sure there will be a lot of crying about it (even though they only have to do it once). Thanks for the help. – Taiter Mar 28 '16 at 17:24
  • Give me a couple hours. I'll get you a step-by-step. – Erin L Mar 28 '16 at 17:57
3
  1. Create a list "Divisions" to hold division names
  2. Create a list "Branches" to hold branch names, with a Lookup field to the Divisions list
  3. Add a Lookup field to "Divisions" and another Lookup field to "Branches" in your main list, where you're trying to limit branches by division.
  4. In your main list, on the List tab in the ribbon, go to List Settings. Click Advanced Settings. Change the last option (Launch forms in a dialog?) to No and click OK.
  5. In your main list, click "Add new item"
  6. On the new item form page, Edit Page (from Site Actions)
  7. Add a Content Editor Web Part and "Click here to add new content"
  8. On the ribbon click HTML and select Edit HTML Source

Add the below code, then click Stop Editing. Repeat for edit form (edit an item, Edit Page, add code, stop editing)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
<script>
    siteURL = "http://yoursiteurl";
    ParentList = "Divisions";
    ChildList = "Branches"; //The list containing branches and a lookup to divisions
    MainList = "Cascading";

    $(document).ready(function(){
        $().SPServices.SPCascadeDropdowns({
            relationshipWebURL: siteURL,
            listName: MainList,
            relationshipList: ChildList, 
            relationshipListParentColumn: "Divisions", //The name of the divisions column in your Branches list
            relationshipListChildColumn: "Title", //The name of the branches column in your Branches list
            relationshipListSortColumn: "Title", //The name of the branches column in your Branches list
            parentColumn: "Division", //The name of the division column in your main list
            childColumn: "Branch" //the name of the branch column in your main list
        });
    });
</script>
1
  • Thank you Erin. Unfortunately I am not able to the Java Script listed because of the strict security policy (one reason no one really wants to use it). Keeping this in my notebook for use elsewhere if possible. – Taiter Apr 21 '16 at 1:50
0

Its hard to give you direct code and promise it works, but maybe you can tweak code that I use. Here is the code I use to hide something on a form. You still need to write your IF type statement for the first drop down though (e.g. If person selects value A hide options 1-4, on drop down B).

    function hideThis(strSearch){
        buildListOfElements();
        var selectedItem = _fieldsHashtable[(strSearch)];
        var itemToHide = selectedItem.parentElement;
        itemToHide.style.display = 'none';
    };

    function buildListOfElements() {
        var formElements = $('#DeltaPlaceHolderMain td.ms-formlabel');
        var formResponses = $('#DeltaPlaceHolderMain td.ms-formbody');
        var len = formElements.length;

        for (i = 0; i < len; i += 1) {
            fieldParams = (formElements[i], formResponses[i]);
            if (null !== fieldParams) {
                var trimedItem = myTrim(formElements[i].innerText);
               _fieldsHashtable[trimedItem] = formResponses[i];
            }
        }
    };
    function myTrim(x) {
        return x.replace(/^\s+|\s+$/gm,'');
    };

You can then use it like: hideThis(label text of field);
You then also need a function for setting the display property to "block" or whatever as well for when you need the field to be visible again. Something like.

function showThis(strSearch){
    buildListOfElements();
    var selectedItem = _fieldsHashtable[(strSearch)];
    var itemToHide = selectedItem.parentElement;
    itemToHide.style.display = '';
};

Not the answer you're looking for? Browse other questions tagged or ask your own question.