File: my_utils.js

package info (click to toggle)
python-trame 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 101,620 kB
  • sloc: python: 13,515; sh: 183; javascript: 93; makefile: 7
file content (23 lines) | stat: -rw-r--r-- 638 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// global trame.utils can be extended by users
// - within template definition, it can be accessed as "utils.my_code.rules.int"
window.trame.utils.my_code = {
    actions: {
        hello(name) {
            alert(`This alert was triggered by my_code for ${name}`)
        },
    },
    rules: {
        number(v) {
            if (Number.isNaN(Number(v))) {
                return "Value needs to be a number";
            }
            return true;
        },
        int(v) {
            if (!Number.isInteger(Number(v))) {
                return "Value needs to be an integer";
            }
            return true;
        }
    }
}