Spaces:
Sleeping
Sleeping
Maryam Ilka commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -601,41 +601,41 @@ def attention_check1():
|
|
| 601 |
key="att1_radio"
|
| 602 |
)
|
| 603 |
|
| 604 |
-
|
| 605 |
-
|
| 606 |
<script>
|
| 607 |
-
function
|
| 608 |
-
// ارسال
|
| 609 |
-
|
|
|
|
|
|
|
|
|
|
| 610 |
}
|
| 611 |
</script>
|
| 612 |
|
| 613 |
-
<button onclick="
|
| 614 |
style="background-color:#28a745; color:white; border:none;
|
| 615 |
border-radius:8px; padding:10px 20px; font-weight:bold;
|
| 616 |
width:100%; cursor:pointer; margin-top:10px;">
|
| 617 |
ادامه
|
| 618 |
</button>
|
| 619 |
"""
|
| 620 |
-
html(
|
| 621 |
|
| 622 |
-
# 2.
|
| 623 |
-
if st.session_state.get("
|
| 624 |
if answer:
|
| 625 |
st.session_state.attention_check1 = answer
|
| 626 |
st.session_state.current_page = "random_likert_questions"
|
|
|
|
| 627 |
st.rerun()
|
| 628 |
else:
|
| 629 |
st.warning("لطفاً یک گزینه را انتخاب کنید")
|
|
|
|
| 630 |
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
document.addEventListener('continueGreenClicked', function() {
|
| 635 |
-
Streamlit.setComponentValue("continue_green_clicked");
|
| 636 |
-
});
|
| 637 |
-
</script>
|
| 638 |
-
""")
|
| 639 |
|
| 640 |
|
| 641 |
def attention_check2():
|
|
|
|
| 601 |
key="att1_radio"
|
| 602 |
)
|
| 603 |
|
| 604 |
+
# 1. تزریق JavaScript برای ارتباط دوطرفه
|
| 605 |
+
js_code = """
|
| 606 |
<script>
|
| 607 |
+
function handleClick() {
|
| 608 |
+
// روش 1: ارسال به sessionState
|
| 609 |
+
Streamlit.setComponentValue("btn_clicked");
|
| 610 |
+
|
| 611 |
+
// روش 2: یا از طریق postMessage
|
| 612 |
+
// window.parent.postMessage("continue_green_clicked", "*");
|
| 613 |
}
|
| 614 |
</script>
|
| 615 |
|
| 616 |
+
<button onclick="handleClick()"
|
| 617 |
style="background-color:#28a745; color:white; border:none;
|
| 618 |
border-radius:8px; padding:10px 20px; font-weight:bold;
|
| 619 |
width:100%; cursor:pointer; margin-top:10px;">
|
| 620 |
ادامه
|
| 621 |
</button>
|
| 622 |
"""
|
| 623 |
+
html(js_code, height=60)
|
| 624 |
|
| 625 |
+
# 2. بررسی کلیک
|
| 626 |
+
if st.session_state.get("btn_clicked"):
|
| 627 |
if answer:
|
| 628 |
st.session_state.attention_check1 = answer
|
| 629 |
st.session_state.current_page = "random_likert_questions"
|
| 630 |
+
time.sleep(0.1) # تأخیر کوتاه برای اطمینان
|
| 631 |
st.rerun()
|
| 632 |
else:
|
| 633 |
st.warning("لطفاً یک گزینه را انتخاب کنید")
|
| 634 |
+
st.session_state.btn_clicked = False # ریست وضعیت
|
| 635 |
|
| 636 |
+
# 3. مقداردهی اولیه session state
|
| 637 |
+
if "btn_clicked" not in st.session_state:
|
| 638 |
+
st.session_state.btn_clicked = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 639 |
|
| 640 |
|
| 641 |
def attention_check2():
|