needs refactoring
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -76,11 +76,11 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user