Tomas Kostovcik
Tomas Kostovcik

Reputation: 11

Python+kivy text input on_text_validate event

I can't find out why this always causes an error:

kv

<OPP_Form>:
    orientation: 'vertical'
    opp_number: kv_OPP_number
    project_name : kv_project_name
    BoxLayout:
        height: "40dp"
        size_hint_y: None
        orientation: "horizontal"
        Label:
            text: "Zadejte OPP cislo"
            multiline: 'False'
            on_text_validate: root.validate_opp()

py

class OPP_Form(BoxLayout):
    def validate_opp(self):
        oppRegex = regex.compile(r'\d\d-\d\d\d\d\d\d')
        if (regex.match(oppRegex, self.opp_number.text) is None):
            print("Wrong OPP number")
        else:
            OPP = self.opp_number.text

I receive the following error:

AttributeError: text_validate File "C:\Data\Anaconda3\envs\opp_folder\lib\site-packages\kivy\lang\builder.py", line 630, in _apply_rule raise AttributeError(key)

What am I doing wrong?

Upvotes: 1

Views: 2652

Answers (1)

joshkmartinez
joshkmartinez

Reputation: 664

I am just adding the answer @PalimPalim had in a comment to help others out

<OPP_Form>:
    orientation: 'vertical'
    opp_number: kv_OPP_number
    project_name : kv_project_name
    BoxLayout:
        height: "40dp"
        size_hint_y: None
        orientation: "horizontal"
        Label:
            text: "Zadejte OPP cislo"
            multiline: 'False'
            on_text: root.validate_opp() //change this line

Upvotes: 2

Related Questions