Validation doesn't work on checkboxes.
See original GitHub issueIt seems to be impossible to raise a validation error on type “checkbox”.
Here is the output I get when I run the “checkbox.py” example, and try to trigger “'You must choose at least one topping.” error message
$ python checkbox.py
😃 Select toppings done
{'toppings': []}
Going into more detail, I tried to make a set of questions with all the ways of making a validation error, all checkboxes should fail in all cases, but only the final “input” case shows an error.
from PyInquirer import style_from_dict, Token, prompt, Separator
from PyInquirer import Validator, ValidationError
class FailValidator(Validator):
def validate(self, document):
raise ValidationError(
message="boogie",
cursor_position=len(document.text)
)
def foo(*args, **kwargs):
raise NotImplementedError("sdfkjsdflj")
questions = [
{
'type': 'checkbox',
'message': 'Select letters',
'name': 'raise exception in function',
'choices': [{"name":"a"}, {"name":"b"}, {"name":"c"}],
'validate': foo,
},
{
'type': 'checkbox',
'message': 'Select letters',
'name': 'lambda false',
'choices': [{"name":"a"}, {"name":"b"}, {"name":"c"}],
'validate': lambda x: False,
},
{
'type': 'checkbox',
'message': 'Select letters',
'name': 'lambda string',
'choices': [{"name":"a"}, {"name":"b"}, {"name":"c"}],
'validate': lambda x: "error message",
},
{
'type': 'checkbox',
'message': 'Select letters',
'name': 'validator validation error',
'choices': [{"name":"a"}, {"name":"b"}, {"name":"c"}],
'validate': FailValidator,
},
{
'type': 'input',
'name': 'text input',
'message': 'Get an error on anything but the empty string.',
'validate': lambda x: x == "" or "Error message",
},
]
answers = prompt(questions)
for name, answer in answers.items():
print(name, answer)
Returns
$ python query-cli.py
? Select letters [a]
? Select letters [a]
? Select letters done
? Select letters done (3 selections)
? Get an error on anything but the empty string.
text input
raise exception in function ['a']
validator validation error ['a', 'b', 'c']
lambda string []
lambda false ['a']
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Checkbox validation not working - Stack Overflow
As @shin mentioned, you need to specify the object of the form during the function call. theForm.declare.checked returns true or false there is ......
Read more >Custom validation doesn't show when working with check boxes
Custom validation should insert error classes for check boxes. What happens instead? It is not submitting the form (assume invalid form) and not ......
Read more >MVC 3 Unobtrusive validation does not work with checkboxes ...
Yes Validation is not performed for checkboxes because the programmers that wrote the adapter says that required is different fro mandatory and in...
Read more >Validation on Checkbox not working - Laracasts
i am trying to get laravel build in validation to work but i now get stuck with some checkboxes. I have some form...
Read more >Checkbox validation problem since last updates | WordPress.org
Hi,. I realized there's a problem with the checkbox validation since last updates. You can see the contact form in the bottom in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just encountered this problem. It would indeed be a nice feature to have.
LOL, I was going nuts thinking that there was something wrong with my code. Good to know that the validator is not yet implemented.