1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-10 18:50:54 +00:00

Prevent special characters in DlgFromDict dictionary causing DOM element selection problems

Use
$.escapeSelector()

Requires jQuery 3.0+
This commit is contained in:
Sijia Zhao 2020-05-19 18:47:16 +01:00
parent 4b064bccc0
commit e907c0c897

View File

@ -130,7 +130,7 @@ export class GUI
htmlCode += '<form>'; htmlCode += '<form>';
for (const key in dictionary) { for (const key in dictionary) {
const value = dictionary[key]; const value = dictionary[key];
const keyId = key + '_id'; const keyId = $.escapeSelector(key) + '_id';
// only create an input if the key is not in the URL: // only create an input if the key is not in the URL:
let inUrl = false; let inUrl = false;
@ -200,7 +200,7 @@ export class GUI
// setup change event handlers for all required keys: // setup change event handlers for all required keys:
for (const key of this._requiredKeys) { for (const key of this._requiredKeys) {
const keyId = key + '_id'; const keyId = $.escapeSelector(key) + '_id';
const input = document.getElementById(keyId); const input = document.getElementById(keyId);
if (input) if (input)
input.onchange = (event) => GUI._onKeyChange(self, event); input.onchange = (event) => GUI._onKeyChange(self, event);
@ -227,7 +227,7 @@ export class GUI
// update dictionary: // update dictionary:
for (const key in dictionary) { for (const key in dictionary) {
const input = document.getElementById(key + "_id"); const input = document.getElementById($.escapeSelector(key) + "_id");
if (input) if (input)
dictionary[key] = input.value; dictionary[key] = input.value;
} }