Attributes Query Param and reserved character "," %2C

Seems that posting the urls on the forum changes their formatting :thinking:

But I do see what you mean. I’ll file this as a bug report for the V2 release but you can test this snippet as a workaround in the meantime.

<script>
  window.fsAttributes = window.fsAttributes || [];
  window.fsAttributes.push([
    'cmsfilter',
    (filterInstances) => {
      console.log('cmsfilter Successfully loaded!');

      const [filterInstance] = filterInstances;

      // Function to get query parameter by name
      function getQueryParam(param) {
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.get(param);
      }

      // Function to select the appropriate option in the dropdown
      function selectJobSector() {
        const sectorParam = getQueryParam('sector');

        if (sectorParam) {
          // Decode the sector parameter to handle any special characters like %2C (comma)
          const decodedSectorParam = decodeURIComponent(sectorParam).replace(/\+/g, ' ');

          // Find the option in the select that matches the decoded sector parameter
          const selectElement = document.getElementById('Job-Sector');
          const options = selectElement.options;

          for (let i = 0; i < options.length; i++) {
            if (options[i].value === decodedSectorParam) {
              selectElement.selectedIndex = i;
              break;
            }
          }
        }
      }

      // Call the function to select the appropriate job sector
      selectJobSector();

      filterInstance.listInstance.on('renderitems', (renderedItems) => {
        console.log(renderedItems);
      });
    },
  ]);
</script>

Let me know if this fixes the issue !

1 Like