151
Views
5
Comments
Filter DropdownSearch with accented words

Hi how are you? We have an Outsystems corporate license and we are using a DropdownSearch widget to get the list of states.

I found it this post: https://www.outsystems.com/forums/discussion/51889/dropdownselect-search-configuration/

I trying use the getFn fuseOptions in advanceFormat in DropdownSearch, but that not work:


    fuseOptions: { 

        getFn: (obj, path) => {   

            var value = Scripts.Fuse.config.getFn(obj, path);

            if (Array.isArray(value)) {

              return value.map(el => removeAccents(el));

            }

            return removeAccents(value);

        

            function removeAccents(obj) {

              if (typeof obj === 'string' || obj instanceof String) {

                return obj.normalize('NFD').replace(/[\u0300-\u036f]/g, '');

              }

              return obj

            }

        }  

    } 

}


We want filter de list from aggregate with and without accented words.

Can you help us ?

Thanks.

2018-10-29 08-31-03
João Marques
 
MVP

Hi Juliano,


Try the following in the advanced format:

{ 

    fuseOptions: { 

        getFn: (obj, path) => {   

            const value = Scripts.Fuse.config.getFn(obj, path);

            if (Array.isArray(value)) {

              return value.map(el => el.normalize('NFD').replace(/[\u0300-\u036F]/g, ''));

            }

        }
    }
}


Kind Regards,
João

UserImage.jpg
Juliano Almeida

Hi João Marques.


I talked to a developer from Outsystems consultancy, and he suggested some modifications, including that the arrow operator does not work in Outsystems.


At the moment we have this:


{

    fuseOptions: {

        threshold: 0.4,

        getFn: function(obj, path) {

            var value = this.getFn(obj, path);

            if (Array.isArray(value)) {

              return value.map(removeAccents);

            }

            return removeAccents(value);

            

            function removeAccents(obj) {

              if (typeof obj === 'string' || obj instanceof String) {

                return obj.normalize('NFD').replace(/[\u0300-\u036f]/g, '');

              }

              return thank you

            }

        }

    }

}


But it still doesn't work.


If I take a test, simply with:


{

    fuseOptions: {

        threshold: 0.4,

        getFn: function(obj, path) {

              console.log('log')

        }

    }

}


She doesn't write any log...


Or point would be this call:

var value = this.getFn(obj, path);


It looks like it can't catch the Fusejs javascript that DropdownSearch uses internally.


Note: We tried to solve our problem by moving the logic to the aggregate, but it didn't work either....


What we need is: to be able to filter a record of an aggregate by one, ignoring if it has an accent, using a DropdownSearch.


Ex.: "sao..." or "são..." return "São Paulo".



Any suggestion. There are some problems.

2018-10-29 08-31-03
João Marques
 
MVP

Hi Juliano,


Have you tried what the advancedFormat I share with you?
I tried with the advanced search I shared with you and I can now get my name when I search without diacritics and before I couldn't:


In my example I'm getting more names than what it is perhaps desirable (Jonas Savimbi doesn't really match Joao) but it would be a matter of adjusting the threshold, I believe.

UserImage.jpg
Juliano Almeida

Hi João,


what he's really doing is this:


"jo_ " ignoring the "ã"


if you see the Fusejs documentation that's what it does.


So if you have a list with


"Biologista"

"Biólogo"


And typing "biol" it doesn't bring the expected result... you would need to write "biolo" for that:



Thanks.


UserImage.jpg
Juliano Almeida

Hi João,

If you try the script in the Fusejs.io live demo (https://fusejs.io/demo.html) you will see that it works.


Thanks.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.