How to enforce Input from JSXGraph in STACK

How to enforce Input from JSXGraph in STACK

by Martin Kraska -
Number of replies: 5

In the attached question I use three input fields bound to three points in a JSXGraph sketch.

As long as the points aren't touched, the input fields remain empty. How can I avoid this? A first idea would be to slightly modify the position of all points in the script and hope that this would trigger update of the input field. 

Empty input fields break the potential response tree, that's why I have to solve the problem.

Average of ratings: -
In reply to Martin Kraska

Re: How to enforce Input from JSXGraph in STACK

by Stephan Bach -

Hi Martin,

one possibility would be to store the coordinates of all three points in one single answer as a list. Then the list won't be empty if at least one point has been moved and you can read the coordinates from this list in your feedback variables. 

Stephan.

In reply to Stephan Bach

Re: How to enforce Input from JSXGraph in STACK

by Martin Kraska -
Hi Stephan, thanks for the hint. The drawback would be that I can't use the convenience binding functions in STACK, as these link single points to single input fields.

var xy = [PunktB.X(), PunktB.Y() ];
PunktB.setPosition( JXG.COORDS_BY_USER,xy);

Once there seems to be no smart way, I have to touch their position individually. This seems to trigger update of the input fields. Yet it is a pity to spoil a question with such bloody workarounds.

The generic way of linking the state to a single string input field is more complex. I use it for an editor of mechanical models (in order to ask students for free body diagrams). The hope was that I can avoid the problem in a less complex way.


In reply to Martin Kraska

Re: How to enforce Input from JSXGraph in STACK

by Martin Kraska -
The above version doesn't work. I had to use this:

// bloody workaround in order to populate the input field from the beginning
var P;
for (P of [PunktB, PunktC, PunktD]) {
var xy1= [P.X()+0.1, P.Y() ];
var xy = [P.X(), P.Y() ];
P.setPosition( JXG.COORDS_BY_USER,xy1);
board.update();
P.setPosition( JXG.COORDS_BY_USER,xy);
board.update();
}
In reply to Martin Kraska

Re: How to enforce Input from JSXGraph in STACK

by Stephan Bach -
Hi Martin,
this is an interesting workaround; good to know, because I have also had this problem. What I don't like so much about the workaround is that it would generate a specific feedback ("wrong answer ...") even if the question had not been answered by the student, right?
(I used to either store all information in one list or I added a note, that all points had to be moved at least once for the question to be marked.)
Stephan.
In reply to Stephan Bach

Re: How to enforce Input from JSXGraph in STACK

by Martin Kraska -
Hi Stephan,
I had to poke around for hours to come to that solution. In my case there are variants where leaving the points where they are is actually the correct answer (if all strain components happen to be zero, which I didn't exclude in the randomization).
The purpose of the workaround is actually to generate specific feedback even if nothing has been done except pressing "check".

I'd expect some method like touch() to exist, which you can call in order to trigger an update. It is interesting that the offset must be big enough to actually shift the point to a different grid snap position. Otherwise the engine is smart enough to check that actually nothing has changed.

Martin