@@ -8,7 +8,7 @@ import { PickerColumn } from '../picker/picker-options';
8
8
import { Form } from '../../util/form' ;
9
9
import { Ion } from '../ion' ;
10
10
import { Item } from '../item/item' ;
11
- import { deepCopy , isBlank , isPresent , isTrueProperty , isArray , isString , assert } from '../../util/util' ;
11
+ import { deepCopy , isBlank , isPresent , isTrueProperty , isArray , isString , assert , clamp } from '../../util/util' ;
12
12
import { dateValueRange , renderDateTime , renderTextFormat , convertFormatToKey , getValueFromFormat , parseTemplate , parseDate , updateDate , DateTimeData , convertDataToISO , daysInMonth , dateSortValue , dateDataSortValue , LocaleData } from '../../util/datetime-util' ;
13
13
14
14
export const DATETIME_VALUE_ACCESSOR : any = {
@@ -514,14 +514,12 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
514
514
picker . refresh ( ) ;
515
515
} ) ;
516
516
517
- picker . present ( pickerOptions ) ;
518
-
519
517
this . _isOpen = true ;
520
518
picker . onDidDismiss ( ( ) => {
521
519
this . _isOpen = false ;
522
520
} ) ;
523
521
524
- picker . refresh ( ) ;
522
+ picker . present ( pickerOptions ) ;
525
523
}
526
524
527
525
/**
@@ -565,7 +563,7 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
565
563
values = dateValueRange ( format , this . _min , this . _max ) ;
566
564
}
567
565
568
- let column : PickerColumn = {
566
+ const column : PickerColumn = {
569
567
name : key ,
570
568
selectedIndex : 0 ,
571
569
options : values . map ( val => {
@@ -578,8 +576,8 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
578
576
579
577
// cool, we've loaded up the columns with options
580
578
// preselect the option for this column
581
- var optValue = getValueFromFormat ( this . _value , format ) ;
582
- var selectedIndex = column . options . findIndex ( opt => opt . value === optValue ) ;
579
+ const optValue = getValueFromFormat ( this . _value , format ) ;
580
+ const selectedIndex = column . options . findIndex ( opt => opt . value === optValue ) ;
583
581
if ( selectedIndex >= 0 ) {
584
582
// set the select index for this column's options
585
583
column . selectedIndex = selectedIndex ;
@@ -589,10 +587,10 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
589
587
picker . addColumn ( column ) ;
590
588
} ) ;
591
589
592
- const min = < any > this . _min ;
593
- const max = < any > this . _max ;
594
590
595
591
// Normalize min/max
592
+ const min = < any > this . _min ;
593
+ const max = < any > this . _max ;
596
594
const columns = this . _picker . getColumns ( ) ;
597
595
[ 'month' , 'day' , 'hour' , 'minute' ]
598
596
. filter ( name => ! columns . find ( column => column . name === name ) )
@@ -620,22 +618,28 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
620
618
const lb = lowerBounds . slice ( ) ;
621
619
const ub = upperBounds . slice ( ) ;
622
620
const options = column . options ;
621
+ let indexMin = options . length - 1 ;
622
+ let indexMax = 0 ;
623
623
624
624
for ( var i = 0 ; i < options . length ; i ++ ) {
625
625
var opt = options [ i ] ;
626
626
var value = opt . value ;
627
627
lb [ index ] = opt . value ;
628
628
ub [ index ] = opt . value ;
629
629
630
- opt . disabled = (
630
+ var disabled = opt . disabled = (
631
631
value < lowerBounds [ index ] ||
632
632
value > upperBounds [ index ] ||
633
633
dateSortValue ( ub [ 0 ] , ub [ 1 ] , ub [ 2 ] , ub [ 3 ] , ub [ 4 ] ) < min ||
634
634
dateSortValue ( lb [ 0 ] , lb [ 1 ] , lb [ 2 ] , lb [ 3 ] , lb [ 4 ] ) > max
635
635
) ;
636
+ if ( ! disabled ) {
637
+ indexMin = Math . min ( indexMin , i ) ;
638
+ indexMax = Math . max ( indexMax , i ) ;
639
+ }
636
640
}
637
-
638
- opt = column . options [ column . selectedIndex ] ;
641
+ let selectedIndex = column . selectedIndex = clamp ( indexMin , column . selectedIndex , indexMax ) ;
642
+ opt = column . options [ selectedIndex ] ;
639
643
if ( opt ) {
640
644
return opt . value ;
641
645
}
0 commit comments