algolia / algolia/instantsearch-android

SearchMode.OnSubmit not working with EditText

Open
#407 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
159
Forks
32
Avg merge
7d 22h
Merged PRs (30d)
2

Description

**Describe the bug 🐛**
i'm using algolia search and instant search library in my project, The problem is that when i set the searchMode to AsYouType the search works perfectly fine and i get the expected results, but when i change it to onSubmit the search will not initiate.

**To Reproduce 🔍**
first i thought that the problem was in the search view from the material components, and since algolia doesn't support it i've changed it to a basic EditText. But even with edit text and it is the same problem.
my plan is to find out how to make it work with the editText and after that use `searchView.editText`, because the `SearchView` has a child `EditText`.

Here's how i declare the edit text in my layout XML file:
`
`

and this is the backend side:

`
private lateinit var connection: ConnectionHandler
private lateinit var recyclerView: RecyclerView
private lateinit var editText: EditText
private lateinit var searchBoxView: SearchBoxViewEditText

// Initialize the HitsSearcher
private val searcher = HitsSearcher(
applicationID = ApplicationID("############"),
apiKey = APIKey("######################"),
indexName = IndexName("###"),
)
private var adapterKt = AdapterKt()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_search_kt, container, false)

editText = view.findViewById(R.id.search)
searchBoxView = SearchBoxViewEditText(editText)

recyclerView = view.findViewById(R.id.recyclerView)
val layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
layoutManager.gapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
recyclerView.layoutManager = layoutManager
recyclerView.adapter = adapterKt

val searchBox = SearchBoxConnector(searcher, searchMode = SearchMode.OnSubmit)
connection = ConnectionHandler(searchBox)
connection += searchBox.connectView(searchBoxView)

connection += searcher.connectHitsView(adapterKt) { response ->
val hits = response.hits.deserialize(PostModelKt.serializer())
adapterKt.setHits(hits) as List
}

searcher.searchAsync()

return view
}`

PS: When using the searchView from ViewAppCompat the search works perfectly fine with onSubmit search mode.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the provided XML EditText, SearchBoxViewEditText, and SearchBoxConnector configured with SearchMode.OnSubmit. Compare its behavior with the working ViewAppCompat SearchView and inspect the submit-event handling in the named search-box components. Done means submitting from the EditText initiates the search and updates the hits as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile, search
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.