I have created a form, and one element creates textboxes based on the number of travellers, it then asks for the ages.
I want it so that if you press enter on the text element, the entered text is added to a list.
I’ve gone through the docs and tried to create that event here, so if 4 text boxes are created, I want 4 entries in my list. I know its not as simple as just adding to the list, because they may change the result, but at least I want to get this bit working.
Also, what I need to append is an int, not a str, because the result will need to be used in an sql select for results containing those ages.
Here is my code
def text_box_travellers_pressed_enter(self, **event_args):
global ages
ages=[]
global trav
trav = int(self.text_box_travellers.text)
trav = trav + 1
global tb
tb = self.tb = {}
self.cp.clear()
for i in range(1, trav):
if i<=4:
row ='A'
elif 5<= i<=8:
row ='B'
elif 9<= i<12:
row ='C'
else:
row ='D'
self.tb[i] = TextBox(bold= True,foreground="#000",background="#fff",placeholder=f"traveller{i}",)
self.tb[i].role = "form-control"
self.tb[i].tag.name = i
self.cp.add_component(self.tb[i], row=row, col_xs=3, width_xs=2)
global age1
age1 = self.tb[i].text
self.tb[i].add_event_handler('x-update', self.add_to_ages)
self.tb[i].raise_event('x-update')
pass
def add_to_ages (self, **event_args):
ages.append(age1)
print(ages)
pass
What I am seeing at the moment on the console is this, so I am appending nothing as nothing has been entered into the boxes yet
['']
['', '']
['', '', '']
['', '', '', '']