Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDTextFieldHelperText not showing when generated at runtime. #1739

Open
MrHxID opened this issue Sep 13, 2024 · 0 comments
Open

MDTextFieldHelperText not showing when generated at runtime. #1739

MrHxID opened this issue Sep 13, 2024 · 0 comments

Comments

@MrHxID
Copy link

MrHxID commented Sep 13, 2024

Description of the Bug

Consider the example below:

# Working Example
from kivymd.app import MDApp
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.textfield import MDTextField, MDTextFieldHelperText


class TestApp(MDApp):
    def build(self):
        return MDFloatLayout(
            md_bg_color=self.theme_cls.surfaceColor,
        )

    def on_start(self):
        self.root.add_widget(
            MDTextField(
                MDTextFieldHelperText(text="Helper Text", mode="persistent"),
                pos_hint={"center": (0.5, 0.5)},
            )
        )


if __name__ == "__main__":
    TestApp().run()

This code will produce an app with a single MDTextField at the center. The text field will have a helper text displaying "Helper Text". So far everything works fine. But now take a look at the following:

# Faulty Example
from kivymd.app import MDApp
from kivymd.uix.button import MDButton, MDButtonText
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.textfield import MDTextField, MDTextFieldHelperText


class TestApp(MDApp):
    def build(self):
        return MDFloatLayout(
            MDButton(
                MDButtonText(text="Show text field"),
                on_release=self.display,
            ),
            md_bg_color=self.theme_cls.surfaceColor,
        )

    def display(self, *_):
        self.root.add_widget(
            MDTextField(
                MDTextFieldHelperText(text="Helper Text", mode="persistent"),
                pos_hint={"center": (0.5, 0.5)},
            )
        )


if __name__ == "__main__":
    TestApp().run()

This app is almost the same as the one above, except that you first have to click the button in the bottom left before the text field appears. However, once the text field has appeared it does not display a helper text.

Side Note:

If you assign the MDTextField to a variable and then call its apply_class_lang_rules method without any arguments, the helper text will actually show up. This is not exactly a fix though, because for a text field with mode="on_error" this would make the helper text show until the text field first receives focus, even if no error is present. After that the helper text will behave as intended.

Versions

  • OS: Windows 10
  • Python: 3.10.11
  • Kivy: 2.3.0
  • KivyMD: 2.0.1.dev0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant