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

Fix Enabling/Disabling MDTextField #1648

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

ikus060
Copy link
Contributor

@ikus060 ikus060 commented Mar 12, 2024

Description of the problem

An exception is raised when enabling or disabling MDTextField. See #1643

Describe the algorithm of actions that leads to the problem

See #1643

Reproducing the problem

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp

KV = '''
<MyView>:

    MDBoxLayout:
        orientation: 'vertical'

        Button:
            text: "Toggle state"
            on_release: root.toggle()

        MDTextField:
            id: field

            MDTextFieldHintText:
                text: "Hint text"

MDScreen:

    MDBoxLayout:
        id: content

        MyView:
'''

class MyView(BoxLayout):

    def toggle(self):
        self.ids['field'].disabled = not self.ids['field'].disabled 

class Example(MDApp):

    def build(self):
        return Builder.load_string(KV)
    
Example().run()

"""


class MainApp(App):
    def build(self):
        self.root = Builder.load_string(kv)


if __name__ == '__main__':
    MainApp().run()

Screenshots of the problem

N/A

Description of Changes

The exception is raised because the function _set_enabled_colors and _set_disabled_colors tried to update the colors of every individual child widget of the MDTextField regardless if the the widget exists or not.

I've added new condition to check if the widget exists before updating the color of it.

Screenshots of the solution to the problem

N/A

Code for testing new changes

Same as above.

@HeaTTheatR HeaTTheatR merged commit 2f26dcc into kivymd:master Mar 12, 2024
3 of 9 checks passed
@ikus060 ikus060 deleted the patrik-fix-textfield-disabled branch March 14, 2024 15:50
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

Successfully merging this pull request may close these issues.

2 participants