Skip to content

Commit

Permalink
Merge pull request #8 from modulr/dev
Browse files Browse the repository at this point in the history
Update 1.0.5
  • Loading branch information
alfredobarron committed May 4, 2016
2 parents bcdfb05 + 7c5fe67 commit e0c7c99
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 63 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mdr-angular-select2",
"version": "1.0.4",
"version": "1.0.5",
"description": "Select2 for angular",
"main": "dist/mdr-select2.js",
"authors": [
Expand Down
51 changes: 21 additions & 30 deletions dist/mdr-select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@
} else {
$scope[options.collection] = data;
initialize();
// Si cambia selected se selecciona el nuevo modelo
if($scope.selected !== undefined){
selected($scope.selected);
}
selected($scope.selected);
}
})
.catch(function (error) {
Expand All @@ -73,32 +70,24 @@
var options = getOptions();
$scope[options.collection] = newValue;
initialize();
// Si cambia selected se selecciona el nuevo modelo
if($scope.selected !== undefined){
selected($scope.selected);
}
selected($scope.selected);
}
});
// Cuando cambia selected se selecciona el nuevo modelo
// Cuando cambia model
$scope.$watch('model', function(newValue, oldValue)
{
// if(newValue !== undefined && newValue !== null){
// if(Object.keys(newValue).length === 0){
// setTimeout(function() {
// $("#selectId_" + $scope.$id).val(null).trigger("change");
// },0);
// }
// }
// Se inicializa el modelo
if(newValue === undefined || newValue === null){
$scope.model = {};
setTimeout(function() {
$("#selectId_" + $scope.$id).val('').trigger('change.select2');
},0);
}
});
// Cuando cambia selected se selecciona el nuevo modelo
// Cuando cambia selected se manda llamar la funcion selected
$scope.$watch('selected', function(newValue, oldValue)
{
if(newValue !== undefined){
selected(newValue);
}
selected(newValue);
});
// Se crea el metodo que inicializa el select2
function initialize()
Expand All @@ -122,16 +111,18 @@
// Selecciona el model(ng-model) y el val en el select2
function selected(value)
{
var options = getOptions();
angular.forEach($scope[options.collection], function(val, key){
if(value == val[options.track]){
$scope.model = val;
setTimeout(function() {
$("#selectId_" + $scope.$id).val(value).trigger("change");
},0);
return false;
}
});
if(value !== undefined){
var options = getOptions();
angular.forEach($scope[options.collection], function(val, key){
if(value == val[options.track]){
$scope.model = val;
setTimeout(function() {
$("#selectId_" + $scope.$id).val(value).trigger("change");
},0);
return false;
}
});
}
}
// Se crea el metodo que obtiene el nombre de la coleccion de options
function getOptions()
Expand Down
2 changes: 1 addition & 1 deletion dist/mdr-select2.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": "mdr-angular-select2",
"version": "1.0.4",
"version": "1.0.5",
"description": "Select2 for angular",
"main": "index.js",
"scripts": {
Expand Down
51 changes: 21 additions & 30 deletions src/mdr-select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@
} else {
$scope[options.collection] = data;
initialize();
// Si cambia selected se selecciona el nuevo modelo
if($scope.selected !== undefined){
selected($scope.selected);
}
selected($scope.selected);
}
})
.catch(function (error) {
Expand All @@ -73,32 +70,24 @@
var options = getOptions();
$scope[options.collection] = newValue;
initialize();
// Si cambia selected se selecciona el nuevo modelo
if($scope.selected !== undefined){
selected($scope.selected);
}
selected($scope.selected);
}
});
// Cuando cambia selected se selecciona el nuevo modelo
// Cuando cambia model
$scope.$watch('model', function(newValue, oldValue)
{
// if(newValue !== undefined && newValue !== null){
// if(Object.keys(newValue).length === 0){
// setTimeout(function() {
// $("#selectId_" + $scope.$id).val(null).trigger("change");
// },0);
// }
// }
// Se inicializa el modelo
if(newValue === undefined || newValue === null){
$scope.model = {};
setTimeout(function() {
$("#selectId_" + $scope.$id).val('').trigger('change.select2');
},0);
}
});
// Cuando cambia selected se selecciona el nuevo modelo
// Cuando cambia selected se manda llamar la funcion selected
$scope.$watch('selected', function(newValue, oldValue)
{
if(newValue !== undefined){
selected(newValue);
}
selected(newValue);
});
// Se crea el metodo que inicializa el select2
function initialize()
Expand All @@ -122,16 +111,18 @@
// Selecciona el model(ng-model) y el val en el select2
function selected(value)
{
var options = getOptions();
angular.forEach($scope[options.collection], function(val, key){
if(value == val[options.track]){
$scope.model = val;
setTimeout(function() {
$("#selectId_" + $scope.$id).val(value).trigger("change");
},0);
return false;
}
});
if(value !== undefined){
var options = getOptions();
angular.forEach($scope[options.collection], function(val, key){
if(value == val[options.track]){
$scope.model = val;
setTimeout(function() {
$("#selectId_" + $scope.$id).val(value).trigger("change");
},0);
return false;
}
});
}
}
// Se crea el metodo que obtiene el nombre de la coleccion de options
function getOptions()
Expand Down

0 comments on commit e0c7c99

Please sign in to comment.