MDTextField update text

368 views
Skip to first unread message

Sadaka Technology

unread,
Jan 9, 2021, 4:44:25 AM1/9/21
to Kivy users support
hello, 

I am using a bind function for MDTextField :

def on_text(self,instance,*args):

I am giving conditions in this function for an MDTextField, which is:


def on_text(self,instance,*args):  

    if instance.text == "" or len(instance.text)<2:
          instance.line_color_focus = 1,0,0,1
    else:
           instance.line_color_focus = 0,0,0,1

# the thing is that the update is coming late, so that even if the text length is equal to 2 ( 3 starting from 0) , it will show red, because the function seems to be reading after I add the text, how can I fix this lag or bug..

Thank you

Sadaka Technology

unread,
Jan 9, 2021, 4:46:00 AM1/9/21
to Kivy users support
and once I delete text upto 2 chars only, I still get   instance.line_color_focus = 0,0,0,1  

Elliot Garbus

unread,
Jan 9, 2021, 8:35:59 AM1/9/21
to kivy-...@googlegroups.com

I don’t see the issue:

 

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

kv =
"""
FloatLayout:
    MyMDTextField:
        pos_hint: {'center_x': 0.5, 'center_y': 0.5}
        size_hint_x: None
        width: 200
        hint_text: "Enter Text Here"
        color_mode: 'custom'

"""


class MyMDTextField(MDTextField):
   
def on_text(self, instance, text):
       
if instance.text == "" or len(instance.text) < 2:
            instance.line_color_focus =
1, 0, 1, 1
       
else:
            instance.line_color_focus =
0, 0, 0, 1


class TestMDTIApp(MDApp):
   
def build(self):
       
return Builder.load_string(kv)

TestMDTIApp().run()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/84715cc8-a37e-4698-b3f1-7646dc659e94n%40googlegroups.com.

 

Sadaka Technology

unread,
Jan 9, 2021, 8:41:47 AM1/9/21
to Kivy users support
actually I am getting names from data base (firebase), so textfield.bind(text=self.getnames)

def getnames(self,instance,*args):
       UrlRequest(...,partial(self.names_on_text,instance)

def names_on_text(self,instance,req,data,*args):
     list = []
    for names in data:
         list.append(names)

      if instance.text == "" or instance in list:
           instance.line_color_focus = 1, 0, 1, 1  
      else:
            instance.line_color_focus = 0, 0, 0, 1  
 
maybe due to that it is getting lagged, also in on_start I am changing the MDTextfield text to a text taken from data, so the on_text function is being called also once from on_start

Elliot Garbus

unread,
Jan 9, 2021, 9:04:04 AM1/9/21
to kivy-...@googlegroups.com

Looks like you are seeing the latency of the url access.  Do you need to do the database access on each letter?  Can you prefetch or cache the database access?

sersa...@outlook.com

unread,
Jan 9, 2021, 9:18:10 AM1/9/21
to kivy-...@googlegroups.com

Hahahaha actually thats why I was thinking about it, using urlrequest it wo t get bugged but will get lagged which means if only, entering once entering 1st letter kivy will assume it is still no letters, once put 2nd letter kivy will assume it is only 1 letter and so on,.  I need to find the names choices field, I mean how can I do that, give the user 3 names outside the list

Saturday, 09 January 2021, 06:04PM +04:00 from Elliot Garbus elli...@cox.net:

Elliot Garbus

unread,
Jan 9, 2021, 9:49:59 AM1/9/21
to kivy-...@googlegroups.com

I don’t understand your question.

Reply all
Reply to author
Forward
0 new messages