Skip to content

Commit 27a464c

Browse files
committed
Select model controller properties $pristine and $touched update after input interaction
1 parent affd759 commit 27a464c

5 files changed

+24
-4
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-selector",
3-
"version": "1.3.13",
3+
"version": "1.3.14",
44
"authors": [
55
"Indri Muska <indrimuska@gmail.com>"
66
],

dist/angular-selector.js

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
var filter = $filter('filter'),
6161
input = angular.element(element[0].querySelector('.selector-input input')),
6262
dropdown = angular.element(element[0].querySelector('.selector-dropdown')),
63+
inputCtrl = input.controller('ngModel'),
64+
selectCtrl = element.find('select').controller('ngModel'),
6365
initDeferred = $q.defer(),
6466
defaults = {
6567
api: {},
@@ -519,6 +521,14 @@
519521
.on('resize', function () {
520522
scope.dropdownPosition();
521523
});
524+
525+
// Update select controller
526+
scope.$watch(function () { return inputCtrl.$pristine; }, function ($pristine) {
527+
selectCtrl[$pristine ? '$setPristine' : '$setDirty']();
528+
});
529+
scope.$watch(function () { return inputCtrl.$touched; }, function ($touched) {
530+
selectCtrl[$touched ? '$setTouched' : '$setUntouched']();
531+
});
522532

523533
// Expose APIs
524534
angular.forEach(['open', 'close', 'fetch'], function (api) {

dist/angular-selector.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-selector",
3-
"version": "1.3.13",
3+
"version": "1.3.14",
44
"description": "A native AngularJS directive that transform a simple `<select>` box into a full html select with typeahead.",
55
"main": "src/angular-selector.js",
66
"repository": {

src/angular-selector.js

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
var filter = $filter('filter'),
6161
input = angular.element(element[0].querySelector('.selector-input input')),
6262
dropdown = angular.element(element[0].querySelector('.selector-dropdown')),
63+
inputCtrl = input.controller('ngModel'),
64+
selectCtrl = element.find('select').controller('ngModel'),
6365
initDeferred = $q.defer(),
6466
defaults = {
6567
api: {},
@@ -519,6 +521,14 @@
519521
.on('resize', function () {
520522
scope.dropdownPosition();
521523
});
524+
525+
// Update select controller
526+
scope.$watch(function () { return inputCtrl.$pristine; }, function ($pristine) {
527+
selectCtrl[$pristine ? '$setPristine' : '$setDirty']();
528+
});
529+
scope.$watch(function () { return inputCtrl.$touched; }, function ($touched) {
530+
selectCtrl[$touched ? '$setTouched' : '$setUntouched']();
531+
});
522532

523533
// Expose APIs
524534
angular.forEach(['open', 'close', 'fetch'], function (api) {

0 commit comments

Comments
 (0)