emvecchi commited on
Commit
dbf0a84
·
verified ·
1 Parent(s): 4320d61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -663,7 +663,7 @@ def show_field(f: Field, index: int, data_collected):
663
  st.session_state.following_mandatory = True
664
 
665
  if f.mandatory or st.session_state.following_mandatory:
666
- f.title += " :red[* required!]" if (validation_error and not SHOW_VALIDATION_ERROR_MESSAGE) else' :red[*]'
667
  f.help = None
668
 
669
  value = st.session_state[key] if key in st.session_state else \
@@ -890,8 +890,19 @@ if 'current_index' not in st.session_state:
890
  st.session_state.current_index = start_index+1
891
  st.session_state.form_displayed = -2
892
 
893
- if 'step' not in st.session_state:
894
- st.session_state.step = 0
 
 
 
 
 
 
 
 
 
 
 
895
 
896
  if get_param_from_url('show_extra_fields'):
897
  fields1 += url_conditional_fields
@@ -939,9 +950,9 @@ elif st.session_state.current_index < len(st.session_state.data):
939
  show_fields(STEPS[step])
940
 
941
  # Action buttons
942
- c1, c2, c3 = st.columns([5,3,2])
943
  with c1:
944
- label = "**:red[Submit]**" if step < total_steps - 1 else "**:red[Submit & next session]**"
945
  if st.button(label):
946
  if validate_current_page(STEPS[step], st.session_state.current_index):
947
  is_last_page = (step == total_steps - 1)
@@ -957,7 +968,7 @@ elif st.session_state.current_index < len(st.session_state.data):
957
  st.session_state.step += 1
958
  st.rerun()
959
  with c2:
960
- if st.button("Previous"):
961
  if step > 0:
962
  st.session_state.step -= 1
963
  st.rerun()
@@ -967,8 +978,6 @@ elif st.session_state.current_index < len(st.session_state.data):
967
  st.rerun()
968
  elif st.session_state.current_index == len(st.session_state.data):
969
  st.write(f"**Thank you for taking part in this study!** \n ")
970
- # if st.button("Previous"):
971
- # navigate(-2)
972
 
973
  # Navigation buttons
974
  #if 0 < st.session_state.current_index < len(st.session_state.data):
 
663
  st.session_state.following_mandatory = True
664
 
665
  if f.mandatory or st.session_state.following_mandatory:
666
+ f.title += " :green[* required!]" if (validation_error and not SHOW_VALIDATION_ERROR_MESSAGE) else' :green[*]'
667
  f.help = None
668
 
669
  value = st.session_state[key] if key in st.session_state else \
 
890
  st.session_state.current_index = start_index+1
891
  st.session_state.form_displayed = -2
892
 
893
+ data = read_saved_data(st.session_state.current_index)
894
+ if data is None:
895
+ st.session_state.step = 0
896
+ else:
897
+ for s, page_fields in enumerate(STEPS):
898
+ if not page_completed(page_fields, data, st.session_state.current_index):
899
+ st.session_state.step = s
900
+ break
901
+ else:
902
+ st.session_state.step = len(STEPS) - 1
903
+ else:
904
+ if 'step' not in st.session_state:
905
+ st.session_state.step = 0
906
 
907
  if get_param_from_url('show_extra_fields'):
908
  fields1 += url_conditional_fields
 
950
  show_fields(STEPS[step])
951
 
952
  # Action buttons
953
+ c1, c2, c3 = st.columns([4,5,4])
954
  with c1:
955
+ label = "**:green[Submit]**" if step < total_steps - 1 else "**:green[Submit & next session]**"
956
  if st.button(label):
957
  if validate_current_page(STEPS[step], st.session_state.current_index):
958
  is_last_page = (step == total_steps - 1)
 
968
  st.session_state.step += 1
969
  st.rerun()
970
  with c2:
971
+ if st.button(":grey[Previous]"):
972
  if step > 0:
973
  st.session_state.step -= 1
974
  st.rerun()
 
978
  st.rerun()
979
  elif st.session_state.current_index == len(st.session_state.data):
980
  st.write(f"**Thank you for taking part in this study!** \n ")
 
 
981
 
982
  # Navigation buttons
983
  #if 0 < st.session_state.current_index < len(st.session_state.data):