Gravatar for wvuong@captechconsulting.com

Question by wvuong, Dec 7, 2015 9:34 PM

Customizing Facet Display Name for Sitecore Checkbox

I have created a facet that maps to a checkbox sitecore field. The facet displays the two possible values as 0 or 1. I would like to customize this to show "yes" or "no" for instance.

Can I customize this without creating my own computed field, or creating a droplink that points to a "yes" and "no" value?

So far the documentation I have read suggests I need to change the sitecore field type and use computed fields.

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Dec 8, 2015 12:44 AM

You can duplicate the standard facet sublayout/view with its ascx/cshtml file and create your own "Checkbox Facet" component from it.

In this component, you will edit the sublayout/view file and use the [valueCaption][1] property of the Coveo JavaScript Search Framework like this:

<script>
  Coveo.$(function() {
    CoveoForSitecore.componentsOptions.<%= Model.UniqueId %> = {
      valueCaption : {
        "0": "No",
        "1": "Yes"
      }
    };
  });
</script>
<div class="CoveoFacet" id='<%= Model.UniqueId %>'
                        All the other data-* attributes present in the original facet file></div>

You will then change your standard facets configured on a checkbox field to use this custom component instead. You will have to define a value for the Unique Id configuration field of your facets too. It's because, by default, the Model.UniqueId value is set to the field name with the @ sign as a prefix (e.g. @fmycheckboxfieldXXXXX). This string is invalid as the ID of an HTML element. By setting the Unique Id field value to a valid HTML element id, you will ensure your HTML and JavaScript code will work correctly.

I hope this helps!

Jeff

Gravatar for wvuong@captechconsulting.com

Comment by wvuong, Dec 8, 2015 10:10 AM

I'm not sure if you meant there was a field where I could enter a custom unique id but I did the following

  @Model.UniqueId.Trim('@')

in order to trim the @ sign and it works perfectly.

Thanks!

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Dec 8, 2015 3:00 PM

Yes, when editing the facet parameters in the Sitecore UI, there's a "Unique Id" field in the "Advanced Settings" section (see Understanding the Coveo Facet Component's Properties).

Ask a question