Skip to content

Commit

Permalink
[UPDATE] Required attr
Browse files Browse the repository at this point in the history
  • Loading branch information
aless673 committed Jul 13, 2017
1 parent 7c51625 commit 7dbaf3d
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/SelectBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"<div class='selectBox {{ngSelectBoxClass}}' ng-click='showSelectModal()'>",
"<span class='selected {{ngPlaceholderClass}}'>{{label}}</span>",
"<span class='selectArrow'>&#9660</span>",
"<input type='hidden' name='{{ngHtmlName}}'/>",
"<input type='hidden' ng-model='ngSelectedValue' name='{{ngHtmlName}}' dynamic-name ng-required='{{ngIsRequired}}'/>",
"</div>"
].join("\n");

Expand All @@ -21,6 +21,7 @@
ngItemId: "@",
ngData: "@",
ngHtmlName: "@",
ngIsRequired: "@",
ngPlaceholder: "@",
ngHeaderClass: "@",
ngSelectChanged: "&",
Expand All @@ -30,6 +31,7 @@
controller: ['$scope', '$element', '$ionicModal', '$parse', function ($scope, $element, $ionicModal, $parse) {

$scope.ngPlaceholder = ($scope.ngPlaceholder) ? $scope.ngPlaceholder : '';
$scope.ngIsRequired = ($scope.ngIsRequired) ? $scope.ngIsRequired : false;
$scope.label = $scope.ngPlaceholder;
$scope.ngPlaceholderClass = ($scope.ngPlaceholderClass) ? $scope.ngPlaceholderClass : '';
$scope.ngSelectBoxClass = ($scope.ngSelectBoxClass) ? $scope.ngSelectBoxClass : '';
Expand All @@ -40,7 +42,7 @@
$scope.ngHeaderClass = ($scope.ngHeaderClass) ? $scope.ngHeaderClass : "";
$scope.renderModal();
$scope.modal.show().then(function(modal) {
$scope.modal.el.style.zIndex = 99;
$scope.modal.el.style.zIndex = 99;
});
};

Expand All @@ -59,19 +61,19 @@
});

$scope.$watch('ngSelectedValue', function (newValue, oldValue) {
//console.log('selected value changed from ', oldValue, ' to ', newValue);
if(undefined != newValue) {
var val = $parse($scope.ngData);
$scope.ngDataObjects = val($scope.$parent);
var i=0, len=$scope.ngDataObjects.length;
for (; i<len; i++) {
if ($scope.ngDataObjects[i][$scope.ngItemId] == newValue) {
//console.log('found descr for ', newValue, ' = ',$scope.ngDataObjects[i][$scope.ngItemName]);
$scope.setPlaceholderLabel($scope.ngDataObjects[i][$scope.ngItemName]);
}
}
} else
$scope.setPlaceholderLabel($scope.ngPlaceholder);
//console.log('selected value changed from ', oldValue, ' to ', newValue);
if(undefined != newValue) {
var val = $parse($scope.ngData);
$scope.ngDataObjects = val($scope.$parent);
var i=0, len=$scope.ngDataObjects.length;
for (; i<len; i++) {
if ($scope.ngDataObjects[i][$scope.ngItemId] == newValue) {
//console.log('found descr for ', newValue, ' = ',$scope.ngDataObjects[i][$scope.ngItemName]);
$scope.setPlaceholderLabel($scope.ngDataObjects[i][$scope.ngItemName]);
}
}
} else
$scope.setPlaceholderLabel($scope.ngPlaceholder);
});

$scope.renderModal = function () {
Expand Down Expand Up @@ -120,6 +122,15 @@
});
}
};
}).directive('dynamicName', function() {
return {
restrict: 'A',
priority: -1,
require: ['ngModel'],
link: function (scope, element, attr, ngModel) {
ngModel[0].$name = attr.name;
}
};
});
//# sourceMappingURL=selectBox.js.map
})();

0 comments on commit 7dbaf3d

Please sign in to comment.