moodle_local_treestudyplan/amd/src/cfg-grades.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-06-03 23:24:16 +02:00
/* eslint-env es6*/
// Put this file in path/to/plugin/amd/src
// You can call it anything you like
/**
* Initialize grade cfg page
*/
export function init() {
2024-06-03 23:24:16 +02:00
{ const
intRx = /\d/,
integerChange = (event) => {
2024-06-03 23:24:16 +02:00
if ((event.key.length > 1) || intRx.test(event.key)
2023-09-08 12:47:29 +02:00
) {
return;
}
event.preventDefault();
};
2023-09-08 12:47:29 +02:00
2024-06-03 23:24:16 +02:00
for (let input of document.querySelectorAll('input[type="number"][step="1"][min="0"]')) {
input.addEventListener("keydown", integerChange);
2023-09-08 12:47:29 +02:00
}
}
2024-06-03 23:24:16 +02:00
{ const
decimal = /^[0-9]*?\.[0-9]*?$/,
intRx = /\d/,
floatChange = (event) => {
2024-06-03 23:24:16 +02:00
if ((event.key.length > 1) || ((event.key === ".") && (!event.currentTarget.value.match(decimal)))
|| intRx.test(event.key)
2023-09-08 12:47:29 +02:00
) {
return;
}
event.preventDefault();
};
2023-09-08 12:47:29 +02:00
2024-06-03 23:24:16 +02:00
for (let input of document.querySelectorAll('input[type="number"][min="0"]:not([step])')) {
input.addEventListener("keydown", floatChange);
2023-09-08 12:47:29 +02:00
}
2024-06-03 23:24:16 +02:00
for (let input of document.querySelectorAll('input[type="text"].float')) {
input.addEventListener("keydown", floatChange);
2023-09-08 12:47:29 +02:00
}
}
}