mirror of
https://github.com/nasa/openmct.git
synced 2025-05-28 13:14:20 +00:00
[Forms] Allow date-time controls to be optional
Don't force date-time inputs to act as if they are required; allow them to be treated as optional, but enforce that this only occurs when left completely empty (as opposed to partially complete.) Supports WTD-1221.
This commit is contained in:
parent
ca4f37b259
commit
45568ecb21
@ -38,7 +38,7 @@
|
||||
placeholder="YYYY-DDD"
|
||||
ng-pattern="/\d\d\d\d-\d\d\d/"
|
||||
ng-model='datetime.date'
|
||||
ng-required='true'/>
|
||||
ng-required='ngRequired || partiallyComplete'/>
|
||||
</span>
|
||||
<span class='field control time sm'>
|
||||
<input type='text'
|
||||
@ -49,7 +49,7 @@
|
||||
integer
|
||||
ng-pattern='/\d+/'
|
||||
ng-model="datetime.hour"
|
||||
ng-required='true'/>
|
||||
ng-required='ngRequired || partiallyComplete'/>
|
||||
</span>
|
||||
<span class='field control time sm'>
|
||||
<input type='text'
|
||||
@ -60,7 +60,7 @@
|
||||
integer
|
||||
ng-pattern='/\d+/'
|
||||
ng-model="datetime.min"
|
||||
ng-required='true'/>
|
||||
ng-required='ngRequired || partiallyComplete'/>
|
||||
</span>
|
||||
<span class='field control time sm'>
|
||||
<input type='text'
|
||||
@ -71,7 +71,7 @@
|
||||
integer
|
||||
ng-pattern='/\d+/'
|
||||
ng-model="datetime.sec"
|
||||
ng-required='true'/>
|
||||
ng-required='ngRequired || partiallyComplete'/>
|
||||
</span>
|
||||
<span class='field control timezone'>
|
||||
UTC
|
||||
|
@ -52,6 +52,20 @@ define(
|
||||
if (fullDateTime.isValid()) {
|
||||
$scope.ngModel[$scope.field] = fullDateTime.valueOf();
|
||||
}
|
||||
|
||||
// If anything is complete, say so in scope; there are
|
||||
// ng-required usages that will update off of this (to
|
||||
// allow datetime to be optional while still permitting
|
||||
// incomplete input)
|
||||
$scope.partiallyComplete =
|
||||
Object.keys($scope.datetime).some(function (key) {
|
||||
return $scope.datetime[key];
|
||||
});
|
||||
|
||||
// Treat empty input as an undefined value
|
||||
if (!$scope.partiallyComplete) {
|
||||
$scope.ngModel[$scope.field] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// Update value whenever any field changes.
|
||||
|
Loading…
x
Reference in New Issue
Block a user