69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
![]() |
/*eslint no-var: "error" */
|
||
|
/*eslint no-unused-vars: "off" */
|
||
|
/*eslint linebreak-style: "off" */
|
||
|
/*eslint no-trailing-spaces: "off" */
|
||
|
/*eslint-env es6*/
|
||
|
// Put this file in path/to/plugin/amd/src
|
||
|
// You can call it anything you like
|
||
|
|
||
|
import {get_string,get_strings} from 'core/str';
|
||
|
import {call} from 'core/ajax';
|
||
|
import Debugger from './debugger';
|
||
|
|
||
|
import {load_strings} from './string-helper';
|
||
|
|
||
|
let debug = new Debugger("treestudyplan-config-grades");
|
||
|
|
||
|
/*
|
||
|
let strings = load_strings({
|
||
|
studyplan: {
|
||
|
studyplan_select_placeholder: 'studyplan_select_placeholder',
|
||
|
},
|
||
|
});
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* Initialize grade cfg page
|
||
|
*/
|
||
|
export function init() {
|
||
|
{ const
|
||
|
intRx = /\d/,
|
||
|
integerChange = (event) => {
|
||
|
if ( (event.key.length > 1) || intRx.test(event.key)
|
||
|
) {
|
||
|
return;
|
||
|
}
|
||
|
event.preventDefault();
|
||
|
};
|
||
|
|
||
|
for (let input of document.querySelectorAll( 'input[type="number"][step="1"][min="0"]' )){
|
||
|
input.addEventListener("keydown", integerChange);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
{ const
|
||
|
decimal= /^[0-9]*?\.[0-9]*?$/,
|
||
|
intRx = /\d/,
|
||
|
floatChange = (event) => {
|
||
|
if ( (event.key.length > 1) || ( (event.key === ".") && (!event.currentTarget.value.match(decimal)) )
|
||
|
|| intRx.test(event.key)
|
||
|
) {
|
||
|
return;
|
||
|
}
|
||
|
event.preventDefault();
|
||
|
};
|
||
|
|
||
|
for (let input of document.querySelectorAll( 'input[type="number"][min="0"]:not([step])' )){
|
||
|
input.addEventListener("keydown", floatChange);
|
||
|
}
|
||
|
for (let input of document.querySelectorAll( 'input[type="text"].float' )){
|
||
|
input.addEventListener("keydown", floatChange);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|