From c424ead8371b11f913f2306721ad7cfa7e9bfc1d Mon Sep 17 00:00:00 2001 From: Vladimir Lugovsky Date: Fri, 22 Apr 2016 21:05:41 +0300 Subject: [PATCH] fix(selectpicker): make possible to use selectpicker with ngOptions Closes #18 --- .../widgets/select/SelectpickerPanelCtrl.js | 38 +++ .../form/inputs/widgets/select/select.html | 238 +++++++++--------- .../widgets/select/selectpicker.directive.js | 25 +- 3 files changed, 176 insertions(+), 125 deletions(-) create mode 100644 src/app/pages/form/inputs/widgets/select/SelectpickerPanelCtrl.js diff --git a/src/app/pages/form/inputs/widgets/select/SelectpickerPanelCtrl.js b/src/app/pages/form/inputs/widgets/select/SelectpickerPanelCtrl.js new file mode 100644 index 0000000..331a8d7 --- /dev/null +++ b/src/app/pages/form/inputs/widgets/select/SelectpickerPanelCtrl.js @@ -0,0 +1,38 @@ +/** + * @author v.lugovsky + * created on 22.04.2016 + */ +(function () { + 'use strict'; + + angular.module('BlurAdmin.pages.form') + .controller('SelectpickerPanelCtrl', SelectpickerPanelCtrl); + + /** @ngInject */ + function SelectpickerPanelCtrl() { + var vm = this; + + vm.standardSelectItems = [ + { label: 'Option 1', value: 1 }, + { label: 'Option 2', value: 2 }, + { label: 'Option 3', value: 3 }, + { label: 'Option 4', value: 4 }, + ]; + + vm.selectWithSearchItems = [ + { label: 'Hot Dog, Fries and a Soda', value: 1 }, + { label: 'Burger, Shake and a Smile', value: 2 }, + { label: 'Sugar, Spice and all things nice', value: 3 }, + { label: 'Baby Back Ribs', value: 4 }, + ]; + + vm.groupedSelectItems = [ + { label: 'Group 1 - Option 1', value: 1, group: 'Group 1' }, + { label: 'Group 2 - Option 2', value: 2, group: 'Group 2' }, + { label: 'Group 1 - Option 3', value: 3, group: 'Group 1' }, + { label: 'Group 2 - Option 4', value: 4, group: 'Group 2' }, + ]; + + } + +})(); diff --git a/src/app/pages/form/inputs/widgets/select/select.html b/src/app/pages/form/inputs/widgets/select/select.html index 408451e..cafd710 100644 --- a/src/app/pages/form/inputs/widgets/select/select.html +++ b/src/app/pages/form/inputs/widgets/select/select.html @@ -1,131 +1,127 @@ -
- -
-
- -
-
- -
-
- -
+
+
+ +
+
+ +
+
+ +
+
+ +
-
-
-
- + +
+
+
+
+ + +
-
-
- + +
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+ +
+ +
+ +
+ +
- -
- -
-
- -
- -
-
-
- -
-
- -
-
- -
-
-
-
- -
- -
- -
- -
- -
-
-
\ No newline at end of file diff --git a/src/app/pages/form/inputs/widgets/select/selectpicker.directive.js b/src/app/pages/form/inputs/widgets/select/selectpicker.directive.js index d959d1b..22e89b4 100644 --- a/src/app/pages/form/inputs/widgets/select/selectpicker.directive.js +++ b/src/app/pages/form/inputs/widgets/select/selectpicker.directive.js @@ -12,10 +12,27 @@ function selectpicker() { return { restrict: 'A', - link: function( $scope, elem) { - setTimeout(function() { - elem.selectpicker({dropupAuto: false}); - }, 0); + require: '?ngOptions', + priority: 1500, // make priority bigger than ngOptions and ngRepeat + link: { + pre: function(scope, elem, attrs) { + elem.append('') + }, + post: function(scope, elem, attrs) { + function refresh() { + elem.selectpicker('refresh'); + } + + if (attrs.ngModel) { + scope.$watch(attrs.ngModel, refresh); + } + + if (attrs.ngDisabled) { + scope.$watch(attrs.ngDisabled, refresh); + } + + elem.selectpicker({ dropupAuto: false, hideDisabled: true }); + } } }; }