diff --git a/src/client/ui/handlers/event.rs b/src/client/ui/handlers/event.rs index d58dca9..a8a0b5c 100644 --- a/src/client/ui/handlers/event.rs +++ b/src/client/ui/handlers/event.rs @@ -67,6 +67,9 @@ impl EventHandler { *current_position = new_position; match app_terminal.get_adresar_by_position(*current_position).await { Ok(response) => { + // Update the ID field - this is what was missing + form_state.id = response.id; + // Update all form fields dynamically form_state.values = vec![ response.firma, @@ -104,6 +107,10 @@ impl EventHandler { if *current_position <= total_count { match app_terminal.get_adresar_by_position(*current_position).await { Ok(response) => { + + // Update the ID field - this was missing + form_state.id = response.id; + // Update all form fields dynamically form_state.values = vec![ response.firma, diff --git a/src/client/ui/handlers/form.rs b/src/client/ui/handlers/form.rs index ff0267b..8248475 100644 --- a/src/client/ui/handlers/form.rs +++ b/src/client/ui/handlers/form.rs @@ -57,6 +57,7 @@ impl FormState { } pub fn reset_to_empty(&mut self) { + self.id = 0; // Reset ID to 0 for new entries self.values.iter_mut().for_each(|v| v.clear()); // Clear all values self.has_unsaved_changes = false; } diff --git a/src/client/ui/handlers/ui.rs b/src/client/ui/handlers/ui.rs index bb3ddff..9748227 100644 --- a/src/client/ui/handlers/ui.rs +++ b/src/client/ui/handlers/ui.rs @@ -76,11 +76,11 @@ pub async fn run_ui() -> Result<(), Box> { form_state.current_field = 0; } else if app_state.current_position >= 1 && app_state.current_position <= total_count { // Existing entry - load data - match app_terminal - .get_adresar_by_position(app_state.current_position) - .await - { + match app_terminal.get_adresar_by_position(app_state.current_position).await { Ok(response) => { + // Set the ID properly + form_state.id = response.id; + // Update form values dynamically form_state.values = vec![ response.firma,