CITGuru / PyInquirer

A Python module for common interactive command line user interfaces
MIT License
1.91k stars 236 forks source link

Custom validator with class attribute #76

Open marino-mrc opened 4 years ago

marino-mrc commented 4 years ago

Hello, I'm trying to write a custom validator using a class. The problem is that I need to compare the value in the validate() method with an attribute of the class. I tried with this: `class MyValidator(Validator): def init(self, limit): self.limit = limit Validator.init(self)

def validate(self, number): if number > limit: return "Error!" else: return True`

The problem is that validate() method seems to be never called with this approach. If I remove the constructor from MyValidator, it works but I don't have the "limit" attribute. Is there a solution for this? Thank you

CITGuru commented 4 years ago

Hmnnn. This seems like you want to be able to pass extra args to the validator???