Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

A new TextInput form erases the value of the previous TextInput

I have this script:

[Prepare Phase]

var.p1 = 0
var.p2 = 0
# a 10x10 form
form1 = Form(cols=[1,1,1,1,1,1,1,1,1,1], rows=[1,1,1,1,1,1,1,1,1,1])
#setting input
text_input1 = TextInput(
		 frame=True, center=False, stub=u'Escribe aquí …',
		return_accepts=True,  var=u'cantidad_sujeto_1') #this var gets erased
form1.set_widget(text_input1, (3, 7), colspan = 4, rowspan = 3)


#setting image
image = ImageWidget(path=pool['1.png'],  adjust=True, frame=False)
form1.set_widget(image, (3, 1), colspan = 4, rowspan = 4)
#setting text
label = Label(text=u'¿Cuanto compartirias con el?', frame=False, center=True)
form1.set_widget(label, (4,6), colspan = 2, rowspan = 1)

#the second form

# a 10x10 form
form2 = Form(cols=[1,1,1,1,1,1,1,1,1,1], rows=[1,1,1,1,1,1,1,1,1,1])
#setting input


text_input2 = TextInput(
		 frame=False, center=False, stub=u'Escribe aquí …',
		return_accepts=True, var=u'cantidad_sujeto_2') #this var makes it to the logger 


form2.set_widget(text_input2, (3, 7), colspan = 4, rowspan = 3)
#setting image
image = ImageWidget(path=pool['2.png'],  adjust=True, frame=False)
form2.set_widget(image, (3, 1), colspan = 4, rowspan = 4)
#setting text
label = Label(text=u'¿Cuanto compartirias con el?', frame=False, center=True)
form2.set_widget(label, (4,6), colspan = 2, rowspan = 1)

[Run Phase]

if var.sujeto == 1:
	form1._exec()
	var.p1 = var.cantidad_sujeto_1 # this var always is 0
if var.sujeto == 2:
	form2._exec()
	var.p2 = var.cantidad_sujeto_2 #this var makes it


What this does is shows 2 different forms in a sequence. Each one with an Image, a text, and an TextInput.

When a variable like 'cantidad_sujeto_2' is submitted (the second form) , it erases the value of the previous TextInput 'cantidad_sujeto_1'.


I tried to store the value in another variable ([p1], [p2]) when the form is submitted (see Run Phase) but it is worthless.

What can i do?

Comments

  • Hi,

    The reason that the variables cantidad_sujeto_1 and cantidad_sujeto_2 are overwritten is that these are reset during the initialization of the TextInput widget in the form. And because both forms are initialized, even if only one of them is executed, both variables get reset.

    You're actually very close to one solution (you can think of several) by assigning the variables directly to p1 and p2, which won't be overwritten. However, at the start of the Prepare, you're explicitly resetting these variables as well!

    var.p1 = 0
    var.p2 = 0
    

    So if you remove those two lines, you should be fine.

    Cheers,

    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

Sign In or Register to comment.