Reactivesearch: Add onValueSelected prop for search components

Created on 8 Feb 2018  路  12Comments  路  Source: appbaseio/reactivesearch

Issue Type:

Enhancement

Description:

Add a new prop onValueSelected to search components DataSearch and CategorySearch. This will accept a function which will be invoked with the current value when the selected value of the component changes (user presses enter or selects a suggestion or clicks outside). In case of autosuggest set to false this behaves like onValueChange.

This prop will eliminate the need of having an extra component watching the search component with react prop. This also solves a use case of only using the search component for suggestions and displaying the results in a different page with the help of URLParams.

Update - We can also extend the CategorySearch by passing the selected category along with the value to this function. A very interesting and useful usecase is using this category to set the value of a different component, say MultiList as in the Car Store example app.

enhancement

Most helpful comment

This will be available in the next release. The docs have been updated for more info:

onValueSelected

is called with the value selected via user interaction. It works only with autosuggest and is called whenever a suggestion is selected or a search is performed either by pressing enter key or the input is blurred.

All 12 comments

Use onQueryChange instead.

onValueChange gets fired while typing and suggestion selection, but onQueryChange only gets fired when the value is selected.

cc: @Guazi - https://codesandbox.io/s/9yz95rnz14

Turns out, the above logic only works with ReactiveList watching the source component, which is not how we should be supporting this. It causes an additional query to fire and also needs additional efforts to visibly hide the unnecessary ReactiveList component from the screen if the user wants to only show a search-box like that of Google's homepage.

Hence, I suggest it'd be best if we support onValueSelected on suggestions-enabled components.

What is a good use-case where someone would want a DataSearch component but not the associated Result component?

Consider this:
you need a page like google homepage, where once the suggestion value is selected, you move to a different page and render results there (like google does with a search-box and results in one page).

I'm looking for something very similar - a universal search bar (Data Search component) in our app header, that renders results on a specific results page that also includes filters.

This will be available in the next release. The docs have been updated for more info:

onValueSelected

is called with the value selected via user interaction. It works only with autosuggest and is called whenever a suggestion is selected or a search is performed either by pressing enter key or the input is blurred.

has this been released? I'm using DataSearch component with onValueSelected set but handler is never invoked. Note: I'm using React Native

@iksnae This isn't available in React Native yet. Doc ref: https://opensource.appbase.io/reactive-manual/native/components/datasearch.html. Can you create an enhancement issue for this? Would you like to take a stab at porting this to the RN lib?

@siddharthlatest thank you. i just took a crack at it and created pull request. https://github.com/appbaseio/reactivesearch/pull/737

The onValueSelected does seem to work with VueJS. Or am I doing something wrong? See code below

<DataSearch
      componentId="search"
      iconPosition="right"
      :dataField="[
        'title',
        'title.autosuggest',
        'title.english',
        'title.keyword',
        'title.search'
    ]"
      class="data-search"
      :showClear="false"
      placeholder="I am looking for"
      :onValueSelected="loadSomething"
    />

why doesn't onValueSelected fire on search icon click?

I have similar problems, how to make it work?

why doesn't onValueSelected fire on search icon click?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

coommark picture coommark  路  4Comments

mrtinkz picture mrtinkz  路  3Comments

ymzoughi picture ymzoughi  路  4Comments

scheiblr picture scheiblr  路  3Comments

danielsnider picture danielsnider  路  4Comments