forked from reidphilpot/data-driven-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditors.js
92 lines (74 loc) · 2.05 KB
/
editors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
define(
[ 'jquery'
, 'slickgrid'
]
, function($) {
function numberEditor(args) {
var input
, defaultValue
this.init = function () {
input = $("<INPUT type=number class='editor-text' />")
if(args.column.min) input.attr('min', args.column.min)
if(args.column.max) input.attr('max', args.column.max)
if(args.column.step) input.attr('step', args.column.step)
input.bind("keydown.nav", function (e) {
if (e.keyCode === $.ui.keyCode.LEFT || e.keyCode === $.ui.keyCode.RIGHT) {
e.stopImmediatePropagation()
}
})
input.appendTo(args.container)
input.focus().select()
}
this.destroy = function () {
input.remove()
}
this.focus = function () {
input.focus()
}
this.loadValue = function (item) {
defaultValue = item[args.column.field]
input.val(defaultValue)
input[0].defaultValue = defaultValue
input.select()
}
this.serializeValue = function () {
return new Number(input.val())
}
this.applyValue = function (item, state) {
item[args.column.field] = state
}
this.isValueChanged = function () {
return (!(input.val() == "" && defaultValue == null)) && (input.val() != defaultValue)
}
this.validate = function () {
if (isNaN(input.val())) {
return {
valid: false
, msg: "Please enter a valid integer"
}
}
if (outOfBounds(input.val())) {
return {
valid: false
, msg: "Value out of bounds"
}
}
return {
valid: true
, msg: null
}
}
this.init()
function outOfBounds(val) {
if (
args.column.min != undefined && input.val() < args.column.min ||
args.column.max != undefined && input.val() > args.column.max
) return true
return false
}
}
return {
number: numberEditor
}
}
)