Skip to content

Use validator in a dialog? #1208

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

Closed
vladdoster opened this issue Aug 9, 2020 · 2 comments
Closed

Use validator in a dialog? #1208

vladdoster opened this issue Aug 9, 2020 · 2 comments

Comments

@vladdoster
Copy link

vladdoster commented Aug 9, 2020

Hello prompt-toolkit team,

You all have created a great module and I really enjoy using it. Bravo!

However, I wish to add a validator to an input dialog, but, alas I'm and idiot and can't see to figure it out. I wish to not wrap it in a while loop. I see the Buffer class and assume it will be something having to do with that.

If we can figure it out together I will add it to examples and/or documentation. I think it would be valuable.

For my prompts I did this

    validator = functools.partial(new_limit_validator, input_type=input_type, curr_lim=curr_lim, op=op)
    validator = Validator.from_callable(validator, 
                                        error_message="New {0} limit must be {1} than {2}".format(name, op, curr_lim.humanized),
                                        move_cursor_to_end=True)
    new_limit_prompt = prompt(text="New {0} limit? format: {1}".format(name, fmt), 
                              validator=validator, 
                              validate_while_typing=False)

I have attempted instantiating a PromptSession object before hand to add my validator to but it isn't inherited by the dialog (makes sense).

Is there anyway I can do something similar with the dialog?

V/R
Vlad

@jonathanslenders
Copy link
Member

Hi @vladdoster,

This change should make it possible: #1246

There's still an issue with the width of the dialog changing after the validation toolbar gets displayed, but that can be fixed.

@trevorbayless
Copy link

#1246 works when pressing Enter on an input_dialog, but the validator doesn't appear to be used when ok_button is selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants