Search code examples
admin-on-rest

AutocompleteInput: change format of query


Is it possible to, for example, change the "q" query key in the AutocompleteInput?

The default { "q": "foobar" } doesn't work with my API where "q" would be correspondent to a model key, e.g productName to make the filtering.

EDIT: (CLOSED) Realizing this isn't really AoR's responsibility I've opted to instead modify my restClient to handle a "q" keyed request.

EDIT 2: This can also be done in the view layer by using the filterToQuery prop on ReferenceInput/ReferenceArrayInput to modify the query sent to your restClient


Solution

  • You can handle this at the client level as well. Just use a custom Rest Client or use a RestClient wrapper to intercept the call to your API and format the request URL depending on the value of the q filter.

    https://marmelab.com/admin-on-rest/RestClients.html#decorating-your-rest-client-example-of-file-upload

    https://marmelab.com/admin-on-rest/RestClients.html#writing-your-own-rest-client

    Hope this helps.