diff --git a/slick.editors.js b/slick.editors.js index 0454450c0..908b3410c 100644 --- a/slick.editors.js +++ b/slick.editors.js @@ -11,6 +11,7 @@ "Editors": { "Text": TextEditor, "Integer": IntegerEditor, + "Float": FloatEditor, "Date": DateEditor, "YesNoSelect": YesNoSelectEditor, "Checkbox": CheckboxEditor, @@ -151,6 +152,68 @@ this.init(); } + function FloatEditor(args) { + var $input; + var defaultValue; + var scope = this; + + this.init = function () { + $input = $(""); + + $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 parseFloat($input.val(), 10) || 0; + }; + + 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 decimal number" + }; + } + + return { + valid: true, + msg: null + }; + }; + + this.init(); + } + function DateEditor(args) { var $input; var defaultValue;