@pxo4 ,
I've spent more time on this than I want to admit -- even though I've not been posting things. I've fruitlessly tried for hours to make this work when I papers that needed graded. I tried change, blur, input, keypress, keyup, keydown, and anything else I could think of. None of them worked. None of them would trigger the event. I even tried things with the isTrusted and it didn't make any difference. Typing the score manually was the only thing I could get to work.
Tonight, I finally got caught up on all my grading and came into the community to catch up. Spotting your message made me try one more time. After about 10 minutes, I gave up and took a different approach. Rather than trying to figure out how to make it work, I focused on the "what changed" portion.
The what changed thing threw me in my previous testing. There was a file with a really enticing name called rubric_assessment.js that was being loaded. I kept on adding break points to it and couldn't get it to fire when I changed stuff. I thought that was just because it was getting loaded before I opened the rubric and enabled the breakpoint, but it turns out that it's not being anymore. It was a red herring.
What changed is that Canvas is using React on the rubrics now. Tonight, I changed my search to include triggering change events in React and came across this post on Stack Overflow: What is the best way to trigger onchange event in react js. That one hit was all I needed (and following some of the links within it) to find the issue and the solution.
Following down that path lead me to a solution that will work. Here it is, line breaking was added to make it display nicely in the Community.
var nativeInputValueSetter =
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
document.getElementById('rubric_full')
.querySelectorAll('tbody.criterions input[type=text]')
.forEach(e => {
var points = 2;
nativeInputValueSetter.call(e, points);
e.dispatchEvent(new Event('change', { 'bubbles': true }));
});
The points = 2 line is just an example. Modifying it slightly to fetch the maximum points from the ENV.rubric.criteria variable, we get this code snippet.
const nativeInputValueSetter =
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
let i = 0;
document.getElementById('rubric_full')
.querySelectorAll('tbody.criterions input[type=text]')
.forEach(e => {
let points = ENV.rubric.criteria[i].points;
nativeInputValueSetter.call(e, points);
e.dispatchEvent(new Event('change', { 'bubbles': true }));
i++;
});
I did not do any error checking, so make sure that you use the tbody as part of the query selector otherwise you will get more inputs than criteria. I get 7 inputs without it but my rubric only has 4.
I checked this with Firefox and Chrome with both free-form comments and ratings that you can click.
Finally, just in case you were curious, the bubbles does need to be there or it doesn't fire.
This has been a wonderful exercise. I have a feeling that it will need to happen a lot more as Canvas moves more and more things to React.
Here are some screen shots to show what's happening. Although this does show the ratings, I have tested it without them.
Before Shot

After shot

After closing Rubric

This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.