Skip to content

Commit df6cb91

Browse files
committed
update demo form
1 parent ba17e06 commit df6cb91

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

reflex_ui/blocks/demo_form.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ def select_field(
120120
label: str,
121121
name: str,
122122
items: list[str],
123-
default: str,
124123
required: bool = False,
125124
) -> rx.Component:
126125
"""Create a labeled select field component.
@@ -129,7 +128,6 @@ def select_field(
129128
label: The label text to display above the select
130129
name: The name attribute for the select field
131130
items: List of options to display in the select
132-
default: The default selected value
133131
required: Whether the field is required
134132
135133
Returns:
@@ -138,10 +136,9 @@ def select_field(
138136
return rx.el.div(
139137
rx.el.label(label, class_name="block text-sm font-medium text-secondary-12"),
140138
ui.select(
141-
placeholder=label,
139+
default_value="Select",
142140
name=name,
143141
items=items,
144-
default_value=default,
145142
required=required,
146143
class_name="w-full",
147144
),
@@ -196,6 +193,16 @@ def check_if_company_email(email: str) -> bool:
196193
return domain not in personal_domains and ".edu" not in domain
197194

198195

196+
def check_if_number_of_employees_is_valid(number_of_employees: str) -> bool:
197+
"""Check if the number of employees is valid."""
198+
return number_of_employees.strip() != "Select"
199+
200+
201+
def check_if_referral_source_is_valid(referral_source: str) -> bool:
202+
"""Check if the referral source is valid."""
203+
return referral_source.strip() != "Select"
204+
205+
199206
class DemoForm(rx.ComponentState):
200207
"""Component state for handling demo form submissions and integrations."""
201208

@@ -216,6 +223,25 @@ async def on_submit(self, form_data: dict[str, Any]):
216223
position="top-center",
217224
)
218225
return
226+
# Check if the has selected a number of employees
227+
if not check_if_number_of_employees_is_valid(
228+
form_data.get("number_of_employees", "")
229+
):
230+
yield rx.toast.error(
231+
"Please select a number of employees",
232+
position="top-center",
233+
)
234+
return
235+
236+
# Check if the has entered a referral source
237+
if not check_if_referral_source_is_valid(
238+
form_data.get("how_did_you_hear_about_us", "")
239+
):
240+
yield rx.toast.error(
241+
"Please select how did you hear about us",
242+
position="top-center",
243+
)
244+
return
219245
# Send to PostHog and Slack for all submissions
220246
await self.send_demo_event(form_data)
221247

@@ -229,7 +255,6 @@ async def on_submit(self, form_data: dict[str, Any]):
229255
)
230256
yield rx.redirect(CAL_REQUEST_DEMO_URL)
231257
return
232-
233258
notes_content = f"""
234259
Name: {form_data.get("first_name", "")} {form_data.get("last_name", "")}
235260
Business Email: {form_data.get("email", "")}
@@ -389,7 +414,6 @@ def get_component(cls, **props):
389414
"Number of employees?",
390415
"number_of_employees",
391416
["1", "2-5", "6-10", "11-50", "51-100", "101-500", "500+"],
392-
"500+",
393417
),
394418
select_field(
395419
"How did you hear about us?",
@@ -402,7 +426,6 @@ def get_component(cls, **props):
402426
"Conference",
403427
"Other",
404428
],
405-
"Google Search",
406429
),
407430
class_name="grid grid-cols-2 gap-4",
408431
),

0 commit comments

Comments
 (0)