Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 22fe903

Browse files
committed
Add the option to define the element's attributes
1 parent d771898 commit 22fe903

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

demo/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ <h2>Define minimum and maximum dates</h2>
5353
<h2>Change strings for months</h2>
5454
<p>Choose a date: <ng-combo-date-picker ng-model="names" ng-months="Enero,Febrero,Marzo,Abril,Mayo,Junio,Julio,Agosto,Septiembre,Octubre,Noviembre,Diciembre"></ng-combo-date-picker></p>
5555
<p>Current selection is: <strong>{{ names }}</strong>
56+
57+
<h2>Define attributtes</h2>
58+
<p>Choose a date: <ng-combo-date-picker ng-model="attrs" ng-attrs-date='{"style": "color:red"}' ng-attrs-month='{"style": "color:green"}' ng-attrs-year='{"style": "color:blue"}'></ng-combo-date-picker></p>
59+
<p>Current selection is: <strong>{{ attrs }}</strong>
5660
</div>
5761
</body>
5862
</html>

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Name | Description
5050
`ngMaxDate` | A _string_ representing the maximum date that can be picked. By default the maximum date is the current day.
5151
`ngMonths` | A _string_ with the names of the twelve months, separated by comma.
5252
`ngOrder` | A _string_ with the characters "d", "m" and "y" indicating in which order the combo boxes must be displayed. By default, the combo boxes are displayed in the order "dmy".
53+
`ngAttrsDate` | A JSON object with the attributes to add to the `select` element for the date.
54+
`ngAttrsMonth` | A JSON object with the attributes to add to the `select` element for the month.
55+
`ngAttrsYear` | A JSON object with the attributes to add to the `select` element for the year.
5356

5457
License
5558
-------

source/ngComboDatePicker.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* ngComboDatePicker v1.0.0
2+
* ngComboDatePicker v1.1.0
33
* http://github.com/jfmdev/ngComboDatePicker
44
* «Copyright 2015 Jose F. Maldonado»
55
* License: LGPLv3 (http://www.gnu.org/licenses/lgpl-3.0.html)
@@ -18,7 +18,10 @@ angular.module("ngComboDatePicker", [])
1818
ngMinDate : '@',
1919
ngMaxDate : '@',
2020
ngMonths : '@',
21-
ngOrder: '@'
21+
ngOrder: '@',
22+
ngAttrsDate: '@',
23+
ngAttrsMonth: '@',
24+
ngAttrsYear: '@'
2225
},
2326
controller: ['$scope', function($scope) {
2427
// Define function for parse dates.
@@ -48,10 +51,25 @@ angular.module("ngComboDatePicker", [])
4851
return res;
4952
}
5053

54+
// Function to parse a JSON object.
55+
function parseJsonPlus(jsonObj) {
56+
var res = null;
57+
if(jsonObj != null) {
58+
try{ res = JSON.parse(jsonObj); }catch(ex) {}
59+
if(res == null) try{ res = JSON.parse(jsonObj.replace(/'/g, '"')); }catch(ex) {}
60+
}
61+
return res;
62+
}
63+
5164
// Initialize model.
5265
$scope.ngModel = parseDate($scope.ngModel);
5366
if($scope.ngModel == null) $scope.ngModel = new Date();
5467

68+
// Initialize attributes variables.
69+
$scope.ngAttrsDate = parseJsonPlus($scope.ngAttrsDate);
70+
$scope.ngAttrsMonth = parseJsonPlus($scope.ngAttrsMonth);
71+
$scope.ngAttrsYear = parseJsonPlus($scope.ngAttrsYear);
72+
5573
// Verify if initial date was defined.
5674
var initDate = parseDate($scope.ngDate);
5775
if(initDate != null) $scope.ngModel = initDate;
@@ -160,13 +178,19 @@ angular.module("ngComboDatePicker", [])
160178
$scope.updateDateList();
161179
};
162180

181+
$scope.getSomething = function() { return 'color:red;'; };
163182
} ],
164183
link: function(scope, element, attrs) {
165184
// Initialize variables.
166185
var jqLite = angular.element;
167186
var children = jqLite(element[0]).children();
168187
var order = scope.ngOrder.split('');
169188

189+
// Add attributes.
190+
if(scope.ngAttrsDate != null) jqLite(children[0]).attr( scope.ngAttrsDate );
191+
if(scope.ngAttrsMonth != null) jqLite(children[1]).attr( scope.ngAttrsMonth );
192+
if(scope.ngAttrsYear != null) jqLite(children[2]).attr( scope.ngAttrsYear );
193+
170194
// Reorder elements.
171195
for(var i=0; i<order.length; i++) {
172196
if(order[i] == 'd') jqLite(element[0]).append(children[0]);

source/ngComboDatePicker.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.

0 commit comments

Comments
 (0)