Autocomplete - Any three characters

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Autocomplete - Any three characters

johnchikm
Is there a way for the Autocomplete to make a suggestion based on any three characters among the items, not just the first three as given in the example.

cheers

John
Reply | Threaded
Open this post in threaded view
|

Re: Autocomplete - Any three characters

Alessandro  Vernet
Administrator
Hi John,

I imagine you're using the autocomplete in the context of a form you've created with Form Builder. If that is the case, then the filtering is done by your service, and you can filter on whatever you want: the autocomplete will just show the results your service returns. Does that help?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Autocomplete - Any three characters

johnchikm
Hi Alex,
this does help me in the right direction thanks.

What we have is a form connecting to an external http service over which we have no control. In one case, filtering on the first three characters is not very helpful - filtering on any three characters WITHIN the returned values will be more helpful to the end users. I think what is required would be a substring 3 to anywhere within the returned values. I understand this would not be very efficient, but the number of values returned would not be that substantial and there is little possibility of the service being changed to return these values in a different format.

regards

John
Reply | Threaded
Open this post in threaded view
|

Re: Autocomplete - Any three characters

Alessandro  Vernet
Administrator
Hi John,

If your service is returning all the values, and there are not too many of them, you could do the filtering in XPath. Ideally, you'd like to write for the "items" expression something like /countries/country[contains(name, $fr-search-value)]. Unfortunately, $fr-search-value is not exposed there. But, temporary, you could write: /countries/country[contains(name, $local/textfield-value)]. This isn't ideal (OK, it is a hack!), but works:

http://i.imgur.com/cTnzh3x.png

E.g. if you want to test for yourself:

http://i.imgur.com/CZLJPBp.png

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Autocomplete - Any three characters

Alessandro  Vernet
Administrator
Hi John,

Since this was a quick thing to do, we enhanced the autocomplete to allow $fr-search-value to be used directly in the "items" expression. This will be in 4.11. And for reference, the issue is:

https://github.com/orbeon/orbeon-forms/issues/2405

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet