Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -403,9 +403,11 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 403 |
st.session_state[key] = INPUT_FIELD_DEFAULT_VALUES[f.type]
|
| 404 |
|
| 405 |
value = st.session_state[key]
|
|
|
|
|
|
|
| 406 |
|
| 407 |
if not SHOW_HELP_ICON:
|
| 408 |
-
|
| 409 |
|
| 410 |
validation_error = False
|
| 411 |
if st.session_state.form_displayed == st.session_state.current_index:
|
|
@@ -422,14 +424,17 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 422 |
st.session_state.following_mandatory = True
|
| 423 |
|
| 424 |
if f.mandatory or st.session_state.following_mandatory:
|
| 425 |
-
|
| 426 |
-
|
|
|
|
|
|
|
|
|
|
| 427 |
|
| 428 |
value = st.session_state[key]
|
| 429 |
|
| 430 |
match f.type:
|
| 431 |
case 'checkbox':
|
| 432 |
-
st.checkbox(f.title, key=key, value=value, help=
|
| 433 |
|
| 434 |
case 'radio':
|
| 435 |
labels = (f.other_params.get('labels')
|
|
@@ -441,13 +446,13 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 441 |
format_func=lambda x: labels[x],
|
| 442 |
key=key,
|
| 443 |
index=value,
|
| 444 |
-
help=
|
| 445 |
horizontal=False
|
| 446 |
)
|
| 447 |
|
| 448 |
case 'slider':
|
| 449 |
st.slider(f.title, min_value=0, max_value=6, step=1, key=key,
|
| 450 |
-
value=value, help=
|
| 451 |
|
| 452 |
case 'select_slider':
|
| 453 |
labels = (f.other_params.get('labels')
|
|
@@ -459,7 +464,7 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 459 |
format_func=lambda x: labels[x // 20],
|
| 460 |
key=key,
|
| 461 |
value=value,
|
| 462 |
-
help=
|
| 463 |
)
|
| 464 |
|
| 465 |
case 'multiselect':
|
|
@@ -473,7 +478,7 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 473 |
key=key,
|
| 474 |
default=value,
|
| 475 |
max_selections=3,
|
| 476 |
-
help=
|
| 477 |
)
|
| 478 |
|
| 479 |
case 'likert_radio':
|
|
@@ -486,7 +491,7 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 486 |
format_func=lambda x: labels[x],
|
| 487 |
key=key,
|
| 488 |
index=value,
|
| 489 |
-
help=
|
| 490 |
horizontal=True
|
| 491 |
)
|
| 492 |
|
|
@@ -500,17 +505,17 @@ def show_field(f: Field, index: int, data_collected):
|
|
| 500 |
format_func=lambda x: labels[x],
|
| 501 |
key=key,
|
| 502 |
index=value,
|
| 503 |
-
help=
|
| 504 |
horizontal=True
|
| 505 |
)
|
| 506 |
|
| 507 |
case 'text':
|
| 508 |
st.text_input(f.title, key=key, value=(value if value is not None else ""),
|
| 509 |
-
max_chars=None, help=
|
| 510 |
|
| 511 |
case 'textarea':
|
| 512 |
st.text_area(f.title, key=key, value=(value if value is not None else ""),
|
| 513 |
-
max_chars=None, help=
|
| 514 |
|
| 515 |
|
| 516 |
|
|
|
|
| 403 |
st.session_state[key] = INPUT_FIELD_DEFAULT_VALUES[f.type]
|
| 404 |
|
| 405 |
value = st.session_state[key]
|
| 406 |
+
|
| 407 |
+
label = f.title
|
| 408 |
|
| 409 |
if not SHOW_HELP_ICON:
|
| 410 |
+
label = f'**{label}**\n\n{f.help}' if f.help else label
|
| 411 |
|
| 412 |
validation_error = False
|
| 413 |
if st.session_state.form_displayed == st.session_state.current_index:
|
|
|
|
| 424 |
st.session_state.following_mandatory = True
|
| 425 |
|
| 426 |
if f.mandatory or st.session_state.following_mandatory:
|
| 427 |
+
label += (" :red[* required!]" if (validation_error and not SHOW_VALIDATION_ERROR_MESSAGE) else " :red[*]")
|
| 428 |
+
#f.title += " :red[* required!]" if (validation_error and not SHOW_VALIDATION_ERROR_MESSAGE) else' :red[*]'
|
| 429 |
+
|
| 430 |
+
help_text = None if not SHOW_HELP_ICON else f.help
|
| 431 |
+
#f.help = None
|
| 432 |
|
| 433 |
value = st.session_state[key]
|
| 434 |
|
| 435 |
match f.type:
|
| 436 |
case 'checkbox':
|
| 437 |
+
st.checkbox(f.title, key=key, value=value, help=help_text)
|
| 438 |
|
| 439 |
case 'radio':
|
| 440 |
labels = (f.other_params.get('labels')
|
|
|
|
| 446 |
format_func=lambda x: labels[x],
|
| 447 |
key=key,
|
| 448 |
index=value,
|
| 449 |
+
help=help_text,
|
| 450 |
horizontal=False
|
| 451 |
)
|
| 452 |
|
| 453 |
case 'slider':
|
| 454 |
st.slider(f.title, min_value=0, max_value=6, step=1, key=key,
|
| 455 |
+
value=value, help=help_text)
|
| 456 |
|
| 457 |
case 'select_slider':
|
| 458 |
labels = (f.other_params.get('labels')
|
|
|
|
| 464 |
format_func=lambda x: labels[x // 20],
|
| 465 |
key=key,
|
| 466 |
value=value,
|
| 467 |
+
help=help_text
|
| 468 |
)
|
| 469 |
|
| 470 |
case 'multiselect':
|
|
|
|
| 478 |
key=key,
|
| 479 |
default=value,
|
| 480 |
max_selections=3,
|
| 481 |
+
help=help_text
|
| 482 |
)
|
| 483 |
|
| 484 |
case 'likert_radio':
|
|
|
|
| 491 |
format_func=lambda x: labels[x],
|
| 492 |
key=key,
|
| 493 |
index=value,
|
| 494 |
+
help=help_text,
|
| 495 |
horizontal=True
|
| 496 |
)
|
| 497 |
|
|
|
|
| 505 |
format_func=lambda x: labels[x],
|
| 506 |
key=key,
|
| 507 |
index=value,
|
| 508 |
+
help=help_text,
|
| 509 |
horizontal=True
|
| 510 |
)
|
| 511 |
|
| 512 |
case 'text':
|
| 513 |
st.text_input(f.title, key=key, value=(value if value is not None else ""),
|
| 514 |
+
max_chars=None, help=help_text)
|
| 515 |
|
| 516 |
case 'textarea':
|
| 517 |
st.text_area(f.title, key=key, value=(value if value is not None else ""),
|
| 518 |
+
max_chars=None, help=help_text)
|
| 519 |
|
| 520 |
|
| 521 |
|