Skip to content

MDTextField breaks MDTextFieldHintText and MDTextFieldHelperText if on_focus is added to its class #1852

@marluna2

Description

@marluna2

Description of the Bug

I don't know why it's like this.
The code should explain it all.

Code and Logs

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.textfield import MDTextField

KV = """
BoxLayout: 
    orientation: "vertical"
    padding: "100dp"
    
    WorkingField:
    Widget:
    BrokenField:
    
<WorkingField>
    MDTextFieldHintText:
        text: "This hint text is working"
    MDTextFieldHelperText:
        text: "This helper text is working"
        mode: "on_focus"
        
<BrokenField>
    MDTextFieldHintText:
        text: "This hint text is broken"
    MDTextFieldHelperText:
        text: "This helper text is broken"
        mode: "on_focus"
"""


class WorkingField(MDTextField):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bind(focus=self.fixed_on_focus)

    def fixed_on_focus(self, _, __):  # on_focus via self.bind works fine
        pass


class BrokenField(MDTextField):
    def on_focus(self, _, __):  # on_focus via function name breaks the field
        pass


class Example(MDApp):
    def build(self):
        self.theme_cls.primary_palette = "Orange"
        self.theme_cls.theme_style = "Dark"
        return Builder.load_string(KV)


Example().run()

Screenshots

Image Image Image

Versions

  • OS: Windows 10
  • Python: 3.10
  • Kivy: 2.3.1
  • KivyMD: 2.0.1.dev0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions