Following on from this topic Can you set a range on a number TextBox - #15 by admin1
I’ve gone back to a TextBox on this part of the quotation, but I still dont like the way its working, I think it has too much potential to mess up the quotation, as - at the moment - if the user went back and changed any of the ages, it would just add another entry to the tuple.
I’d prefer like @david.wylie said to do the calculation later on, when the user clicks submit. So I created this code,
for c in self.column_panel_all_travellers.get_components():
if type(c) is TextBox:
self.tb[i] = self.travage
if self.travage >100:
alert("Age must be less than 100")
else:
self.ages.append(self.travage)
global ages
ages = tuple(self.ages)
print(ages)
It is looping through the TextBoxes, though, in this quote I had 4 TextBoxes, so it did give me 4 results, but all zeros
(0,)
(0, 0)
(0, 0, 0)
(0, 0, 0, 0)
Here is the code that creates the boxes, as you can see I tried to put the tag.name as self.travage, but that hasnt worked.
The only thing that transferred the correct field was sender.text, but you have to click enter each time on a field and then it sets it before the user has clicked submit that they are happy with what they entered. I dont want to do that, I want each box to be treated individually then the calculation done at the end.
#Create Traveller Boxes from Traveller Input
def text_box_travellers_pressed_enter(self, **event_args):
global trav
trav = int(self.text_box_travellers.text)
trav = trav + 1
global tb
tb = self.tb = {}
self.cp.clear()
global i
i = 1
for i in range(1, trav):
self.tb[i] = TextBox(type="number",foreground="#000",background="#fff",placeholder=f"traveller{i}")
self.tb[i].role = "input"
self.tb[i].tag.name = self.travage
self.cp.add_component(self.tb[i], row=1, col_xs=1, width_xs=1)
self.tb[i].set_event_handler('pressed_enter', self.add_to_ages)
Can anyone tell me how I should correctly reference the output of self.tb[ i ]