Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add usage of checkbox answers validator #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions PyInquirer/prompts/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from prompt_toolkit.layout.containers import ConditionalContainer, \
ScrollOffsets, HSplit, Window, WindowAlign
from prompt_toolkit.layout.dimension import LayoutDimension as D
from prompt_toolkit.validation import ValidationError

from prompt_toolkit.layout import Layout

Expand Down Expand Up @@ -160,7 +161,7 @@ def get_prompt_tokens():
' (<up>, <down> to move, <space> to select, <a> '
'to toggle, <i> to invert)'))
if not ic.answered_correctly:
tokens.append((Token.Error, ' Error: %s' % ic.error_message))
tokens.append(('class:Answer', ' Error: %s' % ic.error_message))
return tokens

# assemble layout
Expand Down Expand Up @@ -236,9 +237,13 @@ def _prev():

@kb.add('enter', eager=True)
def set_answer(event):
ic.answered = True
# TODO use validator
event.app.exit(result=ic.get_selected_values())
try:
validator(ic.get_selected_values())
ic.answered = True
event.app.exit(result=ic.get_selected_values())
except ValidationError as error:
ic.error_message = error
ic.answered_correctly = False

return Application(
layout=Layout(layout),
Expand Down