AnsweredAssumed Answered

How do I loop through items in a multiselect in Sugar7?

Question asked by Francesca Shiekh on Jun 27, 2014
Latest reply on Jul 1, 2014 by Cédric Mourizard
Premise: I don't know much javascript and am just starting to learn jQuery, Backbone etc...
But... I'm up for the challenge... again.

I want to create an onchange event which shows/hides given fields based on what is chosen in a multiselect (think dependency on a dropdown but on a multiselect). I don't believe there is anything like that out of the box (If v7 has that please do stop me now!)

In the custom/modules/....../record/record.js script I can fetch the selected values when the onclick event happens:

var selected = this.model.get('departments_using_sitelic_c')

when I console.log(selected) I get
["Aerospace","Art Design "]


What I haven't quite understood is how to then loop through the returned values, eliminate all whitespace and compare the resulting value to some items I stored in a js object, something like:
       var detailsMap = [

          {deptname:'Aerospace',deptfield:'aerospace_details_c'}

         ,{deptname:'ArtDesign',deptfield:'artdesign_details_c'}

       <.... some more.... >

     }

so basically for each selected value I want to get all the whitespace out find the entry that has that deptname and get back the deptfield so I can show it:
    $('[data-name="'+deptfield+'"]').show();



This is quite the learning curve....

Any clues appreciated.

Thanks,


FrancescaS

PS. I also don't know why the onchange event triggers when the page is loaded, but I think that's a common ailment and not just me, in this case I may be ok with it since if there are departments_using_sitelic_c I want to show those detail fields (after I figure out how to hide them all at the beginning of the load process).

Outcomes