maths / moodle-qtype_stack

Stack question type for Moodle
GNU General Public License v3.0
138 stars 147 forks source link

Problems with STACK-JS input access and value setting for inputs of type checkbox, matrix and radiobuttons #1151

Closed bgailer closed 3 months ago

bgailer commented 3 months ago

I have a question in which I want to clear the input for ans1. I was trying to use the new STACK-JS with the function request_access_to_input for that. For algebraic inputs, this works well, but I found some problems when using other input types. As support for changing the value of a textarea was already added because of issue #1123 (thank you very much for the quick response there), I wanted to share the problems I encountered with other inputs here:

All of those input types produce multiple inputs on the VLE side, and that makes it difficult to change the values from the STACK-JS I suppose. So maybe for inputs with multiple values of selected options this is not possible.

As I often only want to clear the input (I think that's the most relevant use case), maybe a new function for doing only that, like for example clear_input(id) that works for all input types would be helpful here.

sangwinc commented 3 months ago

I don't think we anticipated being able to visibly change all the inputs. The original idea was to have a "hidden" algebraic/string input which is changed by JS. I think this might be an expansion of the scope of the feature, although I expect this wasn't really clear in the docs!

aharjula commented 3 months ago

Indeed, not all types of inputs are there; in particular, radio buttons exist primarily for the [[reveal]] block to function, and while one can set the value, clearing it is not really an option currently. Also, in the current form, all inputs, even radio buttons, map to a <input type="hidden"> on the iframe side. Were we to support checkboxes or matrices, things would need to be mapped differently; possibly, we could map those into some form of a JSON dictionary inside that singular input. I really want to keep on mapping VLE side inputs to singular items on the iframe side, just to keep things easy and it is likely that this will mean JSON juggling for checkbox groups and matrices.

I think that I'll expand the interface to include an unset function, but for now checkboxes will stay without support and matrices, well...

Matrices, one can already target cell by cell (just use the suffix to target them), and for those new tools are in the pipeline once we start pushing more metadata (in particular details like decimal separators and dimensions) about inputs out when we print out those inputs. Once that happens, then STACK-JS logic can adapt its behaviour to that metadata, but for now, it will not try to detect the size of a matrix from the inputs present, nor will it try to provide ready-made functions (given a fixed-sized matrix this is basically a simple nested loop) to map into multiple inputs.

When we are dealing with MCQ inputs, we will also need to take into account the issue of their values. Basically, the value the JavaScript code sees might not have anything to do with the actual value going to CAS. And that can be for a good reason, we might have many options with the same value while maintaining input level identity by masking the value with input identifier or we might simply hide the value from the student to avoid information leakage. As long as these kinds of things are in play, interacting with the values of MCQ inputs will always be somewhat complicated, and as those are valid things they will keep on being there.

bgailer commented 3 months ago

Thank you for the explanations and background information here :) I didn’t think of targeting the matrix input cells by using the suffix and will definitely try that in my question.