emvecchi commited on
Commit
d22323b
·
verified ·
1 Parent(s): 50528e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -13
app.py CHANGED
@@ -710,21 +710,37 @@ def show_field(f: Field, index: int, data_collected):
710
  return # done with structural types
711
 
712
  # ---------- Input types (saved to session & later to JSON) ----------
713
- key = f.name + str(index)
714
- # track the logical field name once per page; prep_and_save_data relies on this
715
- st.session_state.data_inputs_keys.append(f.name)
716
-
717
- # Compose title with inline help (no stray/bare expression)
718
- if not SHOW_HELP_ICON:
719
- f.title = f'**{f.title}**\n\n{f.help}' if f.help else f.title
 
720
 
721
  # Resolve initial value: session_state > saved JSON > default
722
- if key in st.session_state:
723
- value = st.session_state[key]
724
- elif data_collected and f.name in data_collected:
725
- value = data_collected[f.name]
726
- else:
727
- value = INPUT_FIELD_DEFAULT_VALUES[f.type]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
728
 
729
  match f.type:
730
  case 'checkbox':
 
710
  return # done with structural types
711
 
712
  # ---------- Input types (saved to session & later to JSON) ----------
713
+ else:
714
+ key = f.name + str(index)
715
+ # track the logical field name once per page; prep_and_save_data relies on this
716
+ st.session_state.data_inputs_keys.append(f.name)
717
+ value = st.session_state[key] if key in st.session_state else \
718
+ (data_collected[f.name] if data_collected else INPUT_FIELD_DEFAULT_VALUES[f.type])
719
+ if not SHOW_HELP_ICON:
720
+ f.title = f'**{f.title}**\n\n{f.help}' if f.help else f.title
721
 
722
  # Resolve initial value: session_state > saved JSON > default
723
+ # if key in st.session_state:
724
+ # value = st.session_state[key]
725
+ # elif data_collected and f.name in data_collected:
726
+ # value = data_collected[f.name]
727
+ # else:
728
+ # value = INPUT_FIELD_DEFAULT_VALUES[f.type]
729
+
730
+ if st.session_state.form_displayed == st.session_state.current_index:
731
+ if st.session_state.following_mandatory and f.skip_mandatory:
732
+ st.session_state.following_mandatory = False
733
+ if f.following_mandatory_values and st.session_state[key] in f.following_mandatory_values:
734
+ st.session_state.following_mandatory = True
735
+ if f.mandatory or st.session_state.following_mandatory:
736
+ if st.session_state[key] == INPUT_FIELD_DEFAULT_VALUES[f.type]:
737
+ st.session_state.valid = False
738
+ validation_error = True
739
+ elif f.following_mandatory_values and st.session_state[key] in f.following_mandatory_values:
740
+ st.session_state.following_mandatory = True
741
+
742
+ value = st.session_state[key] if key in st.session_state else \
743
+ (data_collected[f.name] if data_collected else INPUT_FIELD_DEFAULT_VALUES[f.type])
744
 
745
  match f.type:
746
  case 'checkbox':