Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for preventing submit button when form content is not changed #8918

Closed
kihan2518B opened this issue Oct 24, 2024 · 8 comments
Closed

Comments

@kihan2518B
Copy link
Contributor

Describe the bug
When attempting to update bed or staff details in the facilities section, clicking the "Update" button sends a request to the backend even if no changes have been made to the form. This results in unnecessary API calls, potentially leading to performance issues or confusion in tracking actual updates.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the facilities section.
  2. Select a bed or staff detail to edit.
  3. Without making any changes, click on the "Update" button.
  4. See a network request to update the details

Expected behavior
No request should be sent if no fields are updated, and the "Update" button should remain inactive.

Screenshots
Image

Desktop (please complete the following information):

  • OS: Windows
  • Browser Microsoft Edge
@kihan2518B
Copy link
Contributor Author

I have got a solution for that
solution:
Initial State Tracking:

Capture the initial values of the form fields when the form is first loaded or reset.
On-Change Comparison:

Each time a field is changed, compare the current value with the corresponding initial value for that specific field.
Field-by-Field Tracking:

Maintain a flag (like hasFormChanged) that tracks if any field has been modified compared to its initial value.
Reset Logic:

If a field is changed back to its initial value, reset its modified state, ensuring hasFormChanged becomes false if all fields return to their original values.
Efficient Comparison:

Compare individual fields rather than the entire form object (avoiding JSON.stringify), resulting in better performance and accuracy.
Edge Case Handling:

Ensure that if a field is changed but reverted back to the original value, it doesn't falsely indicate that the form has changed.

Can anyone assign me this issue?

@rithviknishad
Copy link
Member

rithviknishad commented Oct 24, 2024

Let's have this feature in the Form component itself instead.

This way all usages of the Form component would get this feature enabled in one go and not just the form specified in the issue.

We could upgrade the Form component to have a isDirty state. And in the onChange we could set isDirty to true. And the submit button managed by the Form component could be disabled based on this isDirty state.

@github-project-automation github-project-automation bot moved this to Triage in Care Oct 24, 2024
@rithviknishad rithviknishad moved this from Triage to Up Next in Care Oct 24, 2024
@rithviknishad rithviknishad moved this from Up Next to Triage in Care Oct 24, 2024
@kihan2518B
Copy link
Contributor Author

yaa sure that would also work.
@rithviknishad can you assign this issue to me

@rithviknishad rithviknishad moved this from Triage to Up Next in Care Oct 24, 2024
@kihan2518B
Copy link
Contributor Author

I had made necessary changes in the form component.
but this is applying to only patient update form as we have use Form only in PatientRegister component.

Image

For other components like BedCapacity,StaffCapacity, etc we are not using Form component.

So for that I had a solution by manually adding isDirty state to all component.

solution:
Image

@rithviknishad
Copy link
Member

let's switch those to use the Form component instead

@rithviknishad rithviknishad moved this from Up Next to Review required in Care Nov 2, 2024
@rithviknishad rithviknishad changed the title Unnecessary Update Request Triggered Without Changes in Facilities Support for preventing submit button when form content is not changed Nov 2, 2024
@rithviknishad
Copy link
Member

@kihan2518B can we also do the same for what's mentioned in #8982?

@kihan2518B
Copy link
Contributor Author

Yaa sure I will make those component use the form component so that the issues are solved correspondingly

@nihal467
Copy link
Member

Closing this issue, as the entire section of staff and bed capacity has been removed from the CARE platform

@nihal467 nihal467 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
@github-project-automation github-project-automation bot moved this from Review required to Done in Care Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
4 participants