Editor searchList support dynamic search #1515
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1499 and fixes #1498
Actually I ended up rewriting almost the whole shebang as the previous implementation had some bugs and the easiest way to get rid of them was to do it in a another way instead of try to patch it. Most stuff is backwards compatible.
New Features
Fixed Bugs
Breaking Changes
Object.assign()
, but I removed that to only support selected options.Remaining Issues
Usage
Earlier configuration should work with the exception listed in breaking changes. But as the documentation is a bit vague, here comes a complete example of all possible configurations.
All possible configuration
Properties set directly on attribute level is supported as in documentation with the following exceptions/explanations:
required
Optional. true if the input must contain a value. Previous implementation assumed that the value also must be in the list of suggestions.maxLength
: Optional. Max length of input. defaults to 50. I didn't touch that one, it just was not documented.The
list
property works like before, I haven't messed at all with that:It is a list of objects which can either have:
value
and optionally asrc
. The src is an url to an image to display next to the value. The src is relative to the application no matter where configuration comes from, or absolute.location
and aextension
property. The location is an url to a HTML document that contains links to image files, typically a file listing page as generated by a webserver. Alla
tags in the document with the extension extension is used as list values. The filename is the value, and the image itself is displayed next to the value in the drop down. location can not be combined with static list items and can not appear in a list returned from a server using the url option. This is exactly as before.The
config
property can contain the following options:url
Optional. An url to a service that will provide a list object. If specified the staticlist
configuration is ignored. The server should return a JSON list as described above with the exception thatlocation
is not supported as that would be ridiculous. It could be a static file or dynamically generated content.dynamic
Optional. if true theurl
is queried for each key press in the input. The server should accept a query parameter which will receive the current value of the input field. The server should return a list of matching search items. The exact algorithm is up to the server, but origo will assume the list is filtered and sorted so the list will be displayed as is as suggestions, but will be truncated tomaxItems
. If the server's algorithm is not based on substrings of the value, the highlighting may not work as expected.queryParameter
Optional The name of the query parameter to send whendynamic
is true. Defaults toinput
allowOnlyFromList
Optional. true if the user only can input values from the list. Replaces the required validation for list values.disallowDropDown
Optional. If true the very special function to override minChar when input is empty. If not specified, the user can click the down arrow (or enter) when input is empty and get all possible suggestions. Not sure why, but is was there before and seems to sort of mimic a select input. Should most certainly be set to true when using dynamictypeMoreText
Optional. The text to show to the user if the input has less then minChar characters. Defaults to "Skriv fler tecken".noHitsText
Optional. The text to show to the user if there are no suggestions to show. Defaults to "Inga träffar".minChars
Optional. Minimum number of characters required to get a suggestion. Defaults to 2.maxItems
Optional. Maximum number of suggestions to display. Defaults to 10.Here's the code to a test server to be used as url. It works both for dynamic mode and non-dynamic: