Gravatar for

Question by Deb, Sep 15, 2014 11:56 AM

How to get selected facet value in a var?

I would like to get selected facet values in a array var.I am using : $('#myFacet').coveo('getSelectedValues')

It is returning object but not sure how to map exact values of the selection.Please help.

3 Replies
Gravatar for

Answer by Deb, Sep 15, 2014 6:32 PM

Instead of data-id I used id now and it started working..:-)

Gravatar for

Comment by Alexandre Paré, Sep 15, 2014 6:38 PM

if you use data-id you can select it by using $('[data-id="category"]')

Gravatar for

Answer by olamothe, Sep 15, 2014 3:09 PM

What you are doing is correct. It should return an array of selected values (like so : ['value1', 'value2', 'value3', …] )

If there is nothing selected it should return [ ] (an empty array)

Are you sure you are using the correct JQuery selector ? Also, how are you debugging ? Are you trying to alert() the result of the function call ? Alert can not be used to display complex variable correctly (an array for example)

Instead, try to debug using the browser console in any modern browser (Chrome)

Gravatar for

Comment by Deb, Sep 15, 2014 5:29 PM

I am getting json as attached image while executing below code:

 var selectedcategory = $('#category').coveo('getSelectedValues');

log looks like :

don't understand which attribute i should use to get the value?

Gravatar for

Answer by Alexandre Paré, Sep 15, 2014 5:44 PM

I found the issue the selector do not match any dom element. Object[0] is your clue.

Option 1: Your code is not in a JQuery ready function

// Put your code here

Option 2: You do not have any element that have the id "category"

Gravatar for

Comment by Deb, Sep 15, 2014 5:57 PM

I used id as 'data-id' in facet as below:

        <div  data-id="category" class="CoveoHierarchicalFacet" data-title="Category" data-allow-toggling-operator="true" data-show-icon="true" data-field="@sfkbcategoryc"></div>

is there any issue with this id ?

Gravatar for

Comment by Deb, Sep 15, 2014 6:31 PM

It fixed…data-id was not working instead id is working:correct code is:

Ask a question