Skip to content

Commit e0c7c99

Browse files
committed
Merge pull request #8 from modulr/dev
Update 1.0.5
2 parents bcdfb05 + 7c5fe67 commit e0c7c99

File tree

5 files changed

+45
-63
lines changed

5 files changed

+45
-63
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mdr-angular-select2",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Select2 for angular",
55
"main": "dist/mdr-select2.js",
66
"authors": [

dist/mdr-select2.js

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@
5555
} else {
5656
$scope[options.collection] = data;
5757
initialize();
58-
// Si cambia selected se selecciona el nuevo modelo
59-
if($scope.selected !== undefined){
60-
selected($scope.selected);
61-
}
58+
selected($scope.selected);
6259
}
6360
})
6461
.catch(function (error) {
@@ -73,32 +70,24 @@
7370
var options = getOptions();
7471
$scope[options.collection] = newValue;
7572
initialize();
76-
// Si cambia selected se selecciona el nuevo modelo
77-
if($scope.selected !== undefined){
78-
selected($scope.selected);
79-
}
73+
selected($scope.selected);
8074
}
8175
});
82-
// Cuando cambia selected se selecciona el nuevo modelo
76+
// Cuando cambia model
8377
$scope.$watch('model', function(newValue, oldValue)
8478
{
85-
// if(newValue !== undefined && newValue !== null){
86-
// if(Object.keys(newValue).length === 0){
87-
// setTimeout(function() {
88-
// $("#selectId_" + $scope.$id).val(null).trigger("change");
89-
// },0);
90-
// }
91-
// }
79+
// Se inicializa el modelo
9280
if(newValue === undefined || newValue === null){
9381
$scope.model = {};
82+
setTimeout(function() {
83+
$("#selectId_" + $scope.$id).val('').trigger('change.select2');
84+
},0);
9485
}
9586
});
96-
// Cuando cambia selected se selecciona el nuevo modelo
87+
// Cuando cambia selected se manda llamar la funcion selected
9788
$scope.$watch('selected', function(newValue, oldValue)
9889
{
99-
if(newValue !== undefined){
100-
selected(newValue);
101-
}
90+
selected(newValue);
10291
});
10392
// Se crea el metodo que inicializa el select2
10493
function initialize()
@@ -122,16 +111,18 @@
122111
// Selecciona el model(ng-model) y el val en el select2
123112
function selected(value)
124113
{
125-
var options = getOptions();
126-
angular.forEach($scope[options.collection], function(val, key){
127-
if(value == val[options.track]){
128-
$scope.model = val;
129-
setTimeout(function() {
130-
$("#selectId_" + $scope.$id).val(value).trigger("change");
131-
},0);
132-
return false;
133-
}
134-
});
114+
if(value !== undefined){
115+
var options = getOptions();
116+
angular.forEach($scope[options.collection], function(val, key){
117+
if(value == val[options.track]){
118+
$scope.model = val;
119+
setTimeout(function() {
120+
$("#selectId_" + $scope.$id).val(value).trigger("change");
121+
},0);
122+
return false;
123+
}
124+
});
125+
}
135126
}
136127
// Se crea el metodo que obtiene el nombre de la coleccion de options
137128
function getOptions()

dist/mdr-select2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mdr-angular-select2",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Select2 for angular",
55
"main": "index.js",
66
"scripts": {

src/mdr-select2.js

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@
5555
} else {
5656
$scope[options.collection] = data;
5757
initialize();
58-
// Si cambia selected se selecciona el nuevo modelo
59-
if($scope.selected !== undefined){
60-
selected($scope.selected);
61-
}
58+
selected($scope.selected);
6259
}
6360
})
6461
.catch(function (error) {
@@ -73,32 +70,24 @@
7370
var options = getOptions();
7471
$scope[options.collection] = newValue;
7572
initialize();
76-
// Si cambia selected se selecciona el nuevo modelo
77-
if($scope.selected !== undefined){
78-
selected($scope.selected);
79-
}
73+
selected($scope.selected);
8074
}
8175
});
82-
// Cuando cambia selected se selecciona el nuevo modelo
76+
// Cuando cambia model
8377
$scope.$watch('model', function(newValue, oldValue)
8478
{
85-
// if(newValue !== undefined && newValue !== null){
86-
// if(Object.keys(newValue).length === 0){
87-
// setTimeout(function() {
88-
// $("#selectId_" + $scope.$id).val(null).trigger("change");
89-
// },0);
90-
// }
91-
// }
79+
// Se inicializa el modelo
9280
if(newValue === undefined || newValue === null){
9381
$scope.model = {};
82+
setTimeout(function() {
83+
$("#selectId_" + $scope.$id).val('').trigger('change.select2');
84+
},0);
9485
}
9586
});
96-
// Cuando cambia selected se selecciona el nuevo modelo
87+
// Cuando cambia selected se manda llamar la funcion selected
9788
$scope.$watch('selected', function(newValue, oldValue)
9889
{
99-
if(newValue !== undefined){
100-
selected(newValue);
101-
}
90+
selected(newValue);
10291
});
10392
// Se crea el metodo que inicializa el select2
10493
function initialize()
@@ -122,16 +111,18 @@
122111
// Selecciona el model(ng-model) y el val en el select2
123112
function selected(value)
124113
{
125-
var options = getOptions();
126-
angular.forEach($scope[options.collection], function(val, key){
127-
if(value == val[options.track]){
128-
$scope.model = val;
129-
setTimeout(function() {
130-
$("#selectId_" + $scope.$id).val(value).trigger("change");
131-
},0);
132-
return false;
133-
}
134-
});
114+
if(value !== undefined){
115+
var options = getOptions();
116+
angular.forEach($scope[options.collection], function(val, key){
117+
if(value == val[options.track]){
118+
$scope.model = val;
119+
setTimeout(function() {
120+
$("#selectId_" + $scope.$id).val(value).trigger("change");
121+
},0);
122+
return false;
123+
}
124+
});
125+
}
135126
}
136127
// Se crea el metodo que obtiene el nombre de la coleccion de options
137128
function getOptions()

0 commit comments

Comments
 (0)