Skip to content

Fix search button behavior for empty input#2541

Merged
niyajali merged 4 commits intoopenMF:developmentfrom
Shreyash16b:MIFOSAC-505
Jan 26, 2026
Merged

Fix search button behavior for empty input#2541
niyajali merged 4 commits intoopenMF:developmentfrom
Shreyash16b:MIFOSAC-505

Conversation

@Shreyash16b
Copy link
Contributor

@Shreyash16b Shreyash16b commented Nov 14, 2025

Fixes - Jira-#505

Issue : When search button is clicked with empty input field, it showed the previous results.

Before

MIFOSAC-505.Before.mp4

After

MIFOSAC-505.After.mp4

Now :

  • When empty string is searched for, the screen shows empty UI and give Textfield error to enter name or account number.

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Run the static analysis check ./gradlew check or ci-prepush.sh to make sure you didn't break anything

  • If you have multiple commits please combine them into one commit by squashing them.

Summary by CodeRabbit

  • Bug Fixes

    • Input field error text now displays only when the field is actually in an error state.
  • New Features

    • Search now shows inline feedback for empty input to prevent invalid searches.
    • Added a localized message guiding users to enter Name, Account Number, or External ID for search.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 14, 2025

📝 Walkthrough

Walkthrough

MifosOutlinedTextField now shows errorText only when isError is true. SearchViewModel adds showEmptyError to flag empty searches and update results. SearchBox binds its text field's isError and errorText to showEmptyError and a new localized string.

Changes

Cohort / File(s) Summary
Core component update
core/designsystem/src/commonMain/kotlin/com/mifos/core/designsystem/component/MifosOutlinedTextField.kt
Adjusted supportingText branch to render errorText only when isError == true; retains alternate message rendering otherwise.
Search view model
feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt
Added showEmptyError to SearchScreenState. Updated search handling to set showEmptyError = true and reset search results when input is empty; clears the flag when performing a non-empty search.
Search UI
feature/search/src/commonMain/kotlin/com/mifos/feature/search/components/SearchBox.kt
Wired isError to state.showEmptyError and set errorText to the new localized string when true.
Resources
feature/search/src/commonMain/composeResources/values/feature_search_strings.xml
Added feature_search_empty_input_field string: "Please enter Name or Account Number or External ID to search".

Sequence Diagram

sequenceDiagram
    actor User
    participant SearchBox
    participant SearchViewModel
    participant MifosOutlinedTextField

    User->>SearchBox: Trigger search (empty input)
    SearchBox->>SearchViewModel: onSearch("")
    activate SearchViewModel
    SearchViewModel->>SearchViewModel: if input.isEmpty() then showEmptyError=true, searchResult=Empty
    SearchViewModel-->>SearchBox: emit updated state
    deactivate SearchViewModel

    SearchBox->>MifosOutlinedTextField: render with isError=true, errorText="feature_search_empty_input_field"
    activate MifosOutlinedTextField
    Note right of MifosOutlinedTextField: supportingText renders errorText only if isError==true
    MifosOutlinedTextField-->>User: show error message
    deactivate MifosOutlinedTextField
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • revanthkumarJ

Poem

🐇 I nibble bugs and hop on keys,
Blank searches hush beneath the trees.
When fields are empty, I softly chime:
"Fill a name or number next time!"
Hopping off — code spry, error fine.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix search button behavior for empty input' directly describes the main change: preventing the search button from displaying previous results when the input field is empty, and instead showing an error state.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt (1)

42-48: Clear error state when user starts typing.

The error remains visible until the user clicks the search button again, even after they've started typing. For better UX, the error should be cleared immediately when the user updates the search text to a non-empty value.

             is SearchScreenEvent.UpdateSearchText -> {
                 viewModelScope.launch {
                     state.value = state.value.copy(
                         searchText = event.searchText,
+                        showEmptyError = false,
                     )
                 }
             }
🧹 Nitpick comments (1)
feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt (1)

50-58: Consider clearing error state when clearing search text.

When the user explicitly clears the search text, it's a reset action. The error state should probably also be cleared to provide a clean slate.

             is SearchScreenEvent.ClearSearchText -> {
                 viewModelScope.launch {
                     state.value = state.value.copy(
                         searchText = "",
+                        showEmptyError = false,
                     )

                     searchResultState.update { SearchResultState.Empty() }
                 }
             }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87acaa5 and 83a204d.

📒 Files selected for processing (3)
  • core/designsystem/src/commonMain/kotlin/com/mifos/core/designsystem/component/MifosOutlinedTextField.kt (1 hunks)
  • feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt (3 hunks)
  • feature/search/src/commonMain/kotlin/com/mifos/feature/search/components/SearchBox.kt (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: PR Checks / Static Analysis Check
🔇 Additional comments (2)
core/designsystem/src/commonMain/kotlin/com/mifos/core/designsystem/component/MifosOutlinedTextField.kt (1)

210-226: LGTM! Improved consistency of error state handling.

The change ensures that errorText is only rendered when both errorText != null AND isError == true. This prevents the inconsistency where error text could be displayed even when isError is false, which aligns with the explicit error state management introduced in this PR.

feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt (1)

92-132: Good implementation of empty input validation.

The core logic correctly validates search input and provides appropriate feedback:

  • Prevents search execution when input is empty
  • Sets error flag for UI feedback
  • Resets results to empty state
  • Clears error flag when valid search is performed

This successfully addresses the issue where clicking search with empty input showed previous results.

Also applies to: 146-146

Copy link
Contributor

@biplab1 biplab1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the @coderabbitai changes, other than that it looks good to me. This can be merged after the suggested changes are implemented.

Also apply the PR checks before pushing your recent changes to fix build issues in Github Actions.

@amanna13
Copy link
Contributor

@biplab1 I think this PR is ready to be merged.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@feature/search/src/commonMain/composeResources/values/feature_search_strings.xml`:
- Line 18: The string resource feature_search_empty_input_field uses "External
ID" which is inconsistent with the rest of the UI that uses "External Id";
update the value of feature_search_empty_input_field to use "External Id" (i.e.,
"Please enter Name or Account Number or External Id to search") so
capitalization matches existing resources, or if you prefer the "ID" style,
update all other occurrences to "External ID" to keep consistency across the
codebase.

) : ViewModel() {

var state = mutableStateOf(SearchScreenState())
private set
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shreyash16b To improve UI/UX, Stateflow should be used to get the most current state. Although this falls outside the purview of this ticket, a new one can be created for this purpose.

@niyajali niyajali merged commit 1e7dcd2 into openMF:development Jan 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants