diff options
Diffstat (limited to 'src/Widgets.js')
| -rw-r--r-- | src/Widgets.js | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/Widgets.js b/src/Widgets.js index d85c0ddc..d392d285 100644 --- a/src/Widgets.js +++ b/src/Widgets.js @@ -19,25 +19,26 @@ WidgetFactory.prototype = { if (exp) exp = exp.split(':').pop(); var event = "change"; var bubbleEvent = true; + var formatter = angularFormatter[input.attr('ng-format')] || angularFormatter['noop']; if (type == 'button' || type == 'submit' || type == 'reset' || type == 'image') { - controller = new ButtonController(input[0], exp); + controller = new ButtonController(input[0], exp, formatter); event = "click"; bubbleEvent = false; } else if (type == 'text' || type == 'textarea' || type == 'hidden' || type == 'password') { - controller = new TextController(input[0], exp); + controller = new TextController(input[0], exp, formatter); event = "keyup change"; } else if (type == 'checkbox') { - controller = new CheckboxController(input[0], exp); + controller = new CheckboxController(input[0], exp, formatter); event = "click"; } else if (type == 'radio') { - controller = new RadioController(input[0], exp); + controller = new RadioController(input[0], exp, formatter); event="click"; } else if (type == 'select-one') { - controller = new SelectController(input[0], exp); + controller = new SelectController(input[0], exp, formatter); } else if (type == 'select-multiple') { - controller = new MultiSelectController(input[0], exp); + controller = new MultiSelectController(input[0], exp, formatter); } else if (type == 'file') { - controller = this.createFileController(input, exp); + controller = this.createFileController(input, exp, formatter); } else { throw 'Unknown type: ' + type; } @@ -186,8 +187,9 @@ var ButtonController = NullController; /////////////////////// // TextController /////////////////////// -function TextController(view, exp) { +function TextController(view, exp, formatter) { this.view = view; + this.formatter = formatter; this.exp = exp; this.validator = view.getAttribute('ng-validate'); this.required = typeof view.attributes['ng-required'] != "undefined"; @@ -206,7 +208,7 @@ TextController.prototype = { if (this.lastValue === value) { return false; } else { - scope.setEval(this.exp, value); + scope.setEval(this.exp, this.formatter['parse'](value)); this.lastValue = value; return true; } @@ -214,10 +216,10 @@ TextController.prototype = { updateView: function(scope) { var view = this.view; - var value = scope.get(this.exp); + var value = this.formatter['format'](scope.get(this.exp)); if (typeof value === "undefined") { value = this.initialValue; - scope.setEval(this.exp, value); + scope.setEval(this.exp, this.formatter['parse'](value)); } value = value ? value : ''; if (this.lastValue != value) { @@ -248,21 +250,23 @@ TextController.prototype = { /////////////////////// // CheckboxController /////////////////////// -function CheckboxController(view, exp) { +function CheckboxController(view, exp, formatter) { this.view = view; this.exp = exp; this.lastValue = undefined; + this.formatter = formatter; this.initialValue = view.checked ? view.value : ""; }; CheckboxController.prototype = { - updateModel: function(scope) { + updateModel: function(scope) { + jstd.console.log("model"); var input = this.view; var value = input.checked ? input.value : ''; if (this.lastValue === value) { return false; } else { - scope.setEval(this.exp, value); + scope.setEval(this.exp, this.formatter['parse'](value)); this.lastValue = value; return true; } @@ -273,9 +277,10 @@ CheckboxController.prototype = { var value = scope.eval(this.exp); if (typeof value === "undefined") { value = this.initialValue; - scope.setEval(this.exp, value); + scope.setEval(this.exp, this.formatter['parse'](value)); } - input.checked = input.value == (''+value); + value = this.formatter['format'](value); + input.checked = input.value == value; } }; |
