如何从 MDbutton 中的 on_release 触发 MDTextField 中的 on_text_validate?
How to trigger on_text_validate in MDTextField from on_release in MDbutton?
我想在我的 MDTextField: 中通过一个按钮触发 on_text_validate:
。我试图通过在 MDRaisedButton:
中的 on_release:
中编写一些代码来以某种方式绑定它。
我试过了,但没用
ScreenManager:
HomeScreen:
ResultScreen:
<HomeScreen>:
name: 'home'
BoxLayout:
orientation: 'vertical'
spacing: '15dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["menu", lambda x: app.navigation_draw()]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
BoxLayout:
orientation: 'vertical'
MDLabel:
MDTextField:
id: userinput
hint_text: 'DOB in "DD/MM/YYYY" Format'
helper_text: 'Invalid Entry'
helper_text_mode: 'on_error'
size_hint_x: None
width: '225dp'
pos_hint: {"center_x": 0.5}
halign: 'center'
on_quad_touch: None
on_text: None
on_text_validate:
root.inputtextfn()
root.text_validate()
root.manager.current = 'result' if self.error is False else 'home'
BoxLayout:
orientation: 'vertical'
MDRaisedButton:
id: btn
text: 'SUBMIT'
font_size: '15dp'
elevation: 12
md_bg_color: app.theme_cls.primary_color
pos_hint: {"center_x": 0.5}
on_release:
#root.ids.userinput.bind(on_text_validate=self.on_release)
#root.ids.userinput.on_text_validate() == True
MDLabel:
MDLabel:
<ResultScreen>:
name: 'result'
BoxLayout:
orientation: 'vertical'
spacing: '75dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["keyboard-backspace", lambda x: app.set_homescreen() ]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
type: 'top'
pos_hint: {"top":1}
MDLabel:
请帮助修改代码中的注释行。
回答我自己的问题...哈哈。
这个问题只需写
就解决了
root.ids.userinput.dispatch('on_text_validate')
在 on_release:
它工作了,现在代码看起来像这样...
ScreenManager:
HomeScreen:
ResultScreen:
<HomeScreen>:
name: 'home'
BoxLayout:
orientation: 'vertical'
spacing: '15dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["menu", lambda x: app.navigation_draw()]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
BoxLayout:
orientation: 'vertical'
MDLabel:
MDTextField:
id: userinput
hint_text: 'DOB in "DD/MM/YYYY" Format'
helper_text: 'Invalid Entry'
helper_text_mode: 'on_error'
size_hint_x: None
width: '225dp'
pos_hint: {"center_x": 0.5}
halign: 'center'
on_quad_touch: None
on_text: None
on_text_validate:
root.inputtextfn()
root.text_validate()
root.manager.current = 'result' if self.error is False else 'home'
BoxLayout:
orientation: 'vertical'
MDRaisedButton:
id: btn
text: 'SUBMIT'
font_size: '15dp'
elevation: 12
md_bg_color: app.theme_cls.primary_color
pos_hint: {"center_x": 0.5}
on_release:
root.ids.userinput.dispatch('on_text_validate')
MDLabel:
MDLabel:
<ResultScreen>:
name: 'result'
BoxLayout:
orientation: 'vertical'
spacing: '75dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["keyboard-backspace", lambda x: app.set_homescreen() ]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
type: 'top'
pos_hint: {"top":1}
MDLabel:
我想在我的 MDTextField: 中通过一个按钮触发 on_text_validate:
。我试图通过在 MDRaisedButton:
中的 on_release:
中编写一些代码来以某种方式绑定它。
我试过了,但没用
ScreenManager:
HomeScreen:
ResultScreen:
<HomeScreen>:
name: 'home'
BoxLayout:
orientation: 'vertical'
spacing: '15dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["menu", lambda x: app.navigation_draw()]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
BoxLayout:
orientation: 'vertical'
MDLabel:
MDTextField:
id: userinput
hint_text: 'DOB in "DD/MM/YYYY" Format'
helper_text: 'Invalid Entry'
helper_text_mode: 'on_error'
size_hint_x: None
width: '225dp'
pos_hint: {"center_x": 0.5}
halign: 'center'
on_quad_touch: None
on_text: None
on_text_validate:
root.inputtextfn()
root.text_validate()
root.manager.current = 'result' if self.error is False else 'home'
BoxLayout:
orientation: 'vertical'
MDRaisedButton:
id: btn
text: 'SUBMIT'
font_size: '15dp'
elevation: 12
md_bg_color: app.theme_cls.primary_color
pos_hint: {"center_x": 0.5}
on_release:
#root.ids.userinput.bind(on_text_validate=self.on_release)
#root.ids.userinput.on_text_validate() == True
MDLabel:
MDLabel:
<ResultScreen>:
name: 'result'
BoxLayout:
orientation: 'vertical'
spacing: '75dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["keyboard-backspace", lambda x: app.set_homescreen() ]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
type: 'top'
pos_hint: {"top":1}
MDLabel:
请帮助修改代码中的注释行。
回答我自己的问题...哈哈。 这个问题只需写
就解决了root.ids.userinput.dispatch('on_text_validate')
在 on_release:
它工作了,现在代码看起来像这样...
ScreenManager:
HomeScreen:
ResultScreen:
<HomeScreen>:
name: 'home'
BoxLayout:
orientation: 'vertical'
spacing: '15dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["menu", lambda x: app.navigation_draw()]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
BoxLayout:
orientation: 'vertical'
MDLabel:
MDTextField:
id: userinput
hint_text: 'DOB in "DD/MM/YYYY" Format'
helper_text: 'Invalid Entry'
helper_text_mode: 'on_error'
size_hint_x: None
width: '225dp'
pos_hint: {"center_x": 0.5}
halign: 'center'
on_quad_touch: None
on_text: None
on_text_validate:
root.inputtextfn()
root.text_validate()
root.manager.current = 'result' if self.error is False else 'home'
BoxLayout:
orientation: 'vertical'
MDRaisedButton:
id: btn
text: 'SUBMIT'
font_size: '15dp'
elevation: 12
md_bg_color: app.theme_cls.primary_color
pos_hint: {"center_x": 0.5}
on_release:
root.ids.userinput.dispatch('on_text_validate')
MDLabel:
MDLabel:
<ResultScreen>:
name: 'result'
BoxLayout:
orientation: 'vertical'
spacing: '75dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["keyboard-backspace", lambda x: app.set_homescreen() ]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
type: 'top'
pos_hint: {"top":1}
MDLabel: