Gooey 1.0.8.1 Validation Not Working
KianKhadempour opened this issue · comments
Kian Khadempour commented
- OS: Windows 10 Home 22H2
- Python Version: 3.11.4
- Gooey Version: 1.0.8.1
- Thorough description of problem:
Here is my code:
def is_date_valid(date_to_validate: str) -> bool:
try:
datetime.datetime.strptime(date_to_validate, "%Y-%m-%d")
except:
return False
return True
#...
@Gooey(
program_name="...",
disable_stop_button=True,
)
def main():
parser = GooeyParser(
description="...",
)
#...
parser.add_argument(
#...
widget="DateChooser",
gooey_options={
"validator": {
"test": "is_date_valid(user_input)",
"message": "Please enter the date in the correct format (use the Choose date button)",
}
},
)
#...
- Expected Behavior: When inputting the value "2023-06-22", the program should run and not display the message.
- Actual Behavior: The programs does not run and displays the message.
- A minimal code example -- preferably copy/pastable in the issue itself (less time figuring out how to run your code == more time debugging!): Already submitted.
- Screenshot (if visual quirk): N/A
- Anything else you may think will be helpful: The date format is YYYY-MM-DD (padded)
Jan Michalski commented
Hi, I didn't test your code, but it looks like you forgot to enable the Dynamic Validation functionality. Take a look at relevant section in README: Dynamic Validation, especially the How to enable the pre-flight validation subsection. You have to tell Gooey to use the VALIDATE_FORM
event.
Kian Khadempour commented
This was in version 1.0.8, where validation is supposed to (I think) look like this, but I will switch to the 1.2 Alpha if I ever want validation again.