bullet icon indicating copy to clipboard operation
bullet copied to clipboard

[Query] Validator for Input

Open Ccortina opened this issue 4 years ago • 1 comments

Hi , im trying to extend the "Input" class to add a simple folder path validator, but the code seems to be ignoring my accept and valid methods. What am I doing wrong?

from bullet import Input, keyhandler, styles
from bullet.charDef import NEWLINE_KEY
import os.path


class FolderPathCheck(Input):

    @keyhandler.register(NEWLINE_KEY)
    def accept(self):
        if self.valid():
            return super.accept()

    def valid(self, ans):
        return os.path.isdir(self.ans)

Thanks.

Ccortina avatar Oct 16 '20 16:10 Ccortina

super is a function, so accept should return super().accept() NOT super.accept() (notice the parentheses after both super and accept.

Hope that helps!

a-luna avatar Oct 21 '20 14:10 a-luna