This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
forked from 18F/dol-whd-14c
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from AppliedIS/feature-datecomponent
add a date component
- Loading branch information
Showing
7 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
DOL.WHD.Section14c.Web/src/modules/components/dateField/dateFieldController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
import * as _ from 'lodash'; | ||
|
||
module.exports = function(ngModule) { | ||
ngModule.controller('dateFieldController', function($scope, moment) { | ||
'ngInject'; | ||
'use strict'; | ||
|
||
var vm = this; | ||
|
||
function updateLocalScope() { | ||
if(moment.isDate($scope.dateVal)) { | ||
const dateValMoment = moment($scope.dateVal); | ||
// parse out values | ||
vm.month = dateValMoment.month() + 1; // month is zero-based | ||
vm.day = dateValMoment.date(); | ||
vm.year = dateValMoment.year(); | ||
} | ||
} | ||
|
||
$scope.$watch('dateVal', function(newValue, oldValue) { | ||
if(moment.isDate(newValue) && !moment(newValue).isSame(oldValue)) { | ||
updateLocalScope(); | ||
} | ||
}); | ||
|
||
$scope.$watchGroup(['vm.year', 'vm.month', 'vm.day'], function(newValues, oldValues) { | ||
if(_.difference(newValues, oldValues).length > 0 && vm.year && vm.month && vm.day) { | ||
$scope.dateVal = new Date(vm.year, vm. month - 1, vm.day); | ||
} | ||
}); | ||
|
||
updateLocalScope(); | ||
}); | ||
} |
18 changes: 18 additions & 0 deletions
18
DOL.WHD.Section14c.Web/src/modules/components/dateField/dateFieldDirective.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
module.exports = function(ngModule) { | ||
ngModule.directive('dateField', function() { | ||
|
||
'use strict'; | ||
|
||
return { | ||
restrict: 'EA', | ||
template: require('./dateFieldTemplate.html'), | ||
controller: 'dateFieldController', | ||
scope: { | ||
dateVal: '=' | ||
}, | ||
controllerAs: 'vm' | ||
}; | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
DOL.WHD.Section14c.Web/src/modules/components/dateField/dateFieldTemplate.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="usa-date-of-birth"> | ||
<div class="usa-form-group usa-form-group-month"> | ||
<label for="{{::$id}}_Month">Month</label> | ||
<input class="usa-input-inline" aria-describedby="dobHint" class="usa-form-control" id="{{::$id}}_Month" name="{{::$id}}_Month" pattern="0?[1-9]|1[012]" type="number" min="1" max="12" value="" ng-model="vm.month"> | ||
</div> | ||
<div class="usa-form-group usa-form-group-day"> | ||
<label for="{{::$id}}_Day">Day</label> | ||
<input class="usa-input-inline" aria-describedby="dobHint" class="usa-form-control" id="{{::$id}}_Day" name="{{::$id}}_Day" pattern="0?[1-9]|1[0-9]|2[0-9]|3[01]" type="number" min="1" max="31" value="" ng-model="vm.day"> | ||
</div> | ||
<div class="usa-form-group usa-form-group-year"> | ||
<label for="{{::$id}}_Year">Year</label> | ||
<input class="usa-input-inline" aria-describedby="dobHint" class="usa-form-control" id="{{::$id}}_Year" name="{{::$id}}_Year" pattern="[0-9]{4}" type="number" min="1900" max="3000" value="" ng-model="vm.year"> | ||
</div> | ||
</div> |
6 changes: 6 additions & 0 deletions
6
DOL.WHD.Section14c.Web/src/modules/components/dateField/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = function(ngModule) { | ||
require('./dateFieldController')(ngModule); | ||
require('./dateFieldDirective')(ngModule); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters