Skip to content

Commit

Permalink
Ajusta problema onde o valor preenchido dentro de uma requisição assi…
Browse files Browse the repository at this point in the history
…ncrona estava sendo perdido.
  • Loading branch information
tiagor87 committed Jan 9, 2016
1 parent f288a97 commit f1a6623
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "n4-numberinput-directive",
"main": "dist/n4numberinput.js",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com//n4numberinput",
"authors": [
"N4Works <contato@n4works.com>"
Expand Down
4 changes: 2 additions & 2 deletions dist/n4numberinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
}
return value.trim().replace(/[^0-9]/g, "");
},
parseValue = function(value) {
parseValue = function(value, oldValue) {
var formattedValue = getFormattedValue(value);

if (formattedValue !== value) {
if ((formattedValue !== value) && (!!formattedValue ^ !!oldValue)) {
controller.$setViewValue(formattedValue);
controller.$render();
}
Expand Down
2 changes: 1 addition & 1 deletion dist/n4numberinput.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "n4-numberinput-directive",
"version": "1.0.0",
"version": "1.0.1",
"main": "src/n4numberinput.js",
"scripts":
{
Expand Down
23 changes: 23 additions & 0 deletions sample/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample</title>
</head>
<body ng-app="sample" ng-controller="RootController as controller">
{{value}}
<input n4-number-input type="text" name="name" value="" ng-model="value">
</body>
<script type="text/javascript" src="../bower_components/angular/angular.js"></script>
<script type="text/javascript" src="../src/n4numberinput.js"></script>
<script type="text/javascript">
"use strict";

angular.module("sample", ["n4NumberInput"])
.controller("RootController", function ($rootScope, $timeout) {
$timeout(function () {
$rootScope.value = "21484441000186";
});
});
</script>
</html>
4 changes: 2 additions & 2 deletions src/n4numberinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
}
return value.trim().replace(/[^0-9]/g, "");
},
parseValue = function(value) {
parseValue = function(value, oldValue) {
var formattedValue = getFormattedValue(value);

if (formattedValue !== value) {
if ((formattedValue !== value) && (!!formattedValue ^ !!oldValue)) {
controller.$setViewValue(formattedValue);
controller.$render();
}
Expand Down
13 changes: 11 additions & 2 deletions tests/n4numberinput_test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';

describe('n4NumberInput', function() {
var $scope, $compile;
var $scope, $compile, $timeout;

beforeEach(module('n4NumberInput'));

beforeEach(inject(function(_$rootScope_, _$compile_) {
beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_) {
$scope = _$rootScope_.$new();
$compile = _$compile_;
$timeout = _$timeout_;
}));

describe('Creation', function() {
Expand Down Expand Up @@ -73,5 +74,13 @@ describe('n4NumberInput', function() {
expect($scope.value).toBe('0123456789');
expect(element.val()).toBe('0123456789');
});

it('Shoud fullfill the input on async method', function () {
$timeout(function () {
$scope.value = '21484441000186';
});
$timeout.flush();
expect(element.val()).toBe('21484441000186')
})
});
});

0 comments on commit f1a6623

Please sign in to comment.