diff options
author | MG12 <wuzhao.mail@gmail.com> | 2015-12-12 20:34:00 +0800 |
---|---|---|
committer | MG12 <wuzhao.mail@gmail.com> | 2015-12-12 20:34:00 +0800 |
commit | 518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6 (patch) | |
tree | 664ef5377589dc3c4def7e732dfaa76e89da1fb1 /src/module/Header.jsx | |
parent | 182e9fccc90ae709322b7cc314c8775a9d8d46b8 (diff) | |
download | time-picker-518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6.tar.gz time-picker-518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6.tar.zst time-picker-518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6.zip |
add new options about disabled time
Diffstat (limited to 'src/module/Header.jsx')
-rw-r--r-- | src/module/Header.jsx | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/module/Header.jsx b/src/module/Header.jsx index ef88948..c2f8eef 100644 --- a/src/module/Header.jsx +++ b/src/module/Header.jsx | |||
@@ -13,6 +13,9 @@ const Header = React.createClass({ | |||
13 | hourOptions: PropTypes.array, | 13 | hourOptions: PropTypes.array, |
14 | minuteOptions: PropTypes.array, | 14 | minuteOptions: PropTypes.array, |
15 | secondOptions: PropTypes.array, | 15 | secondOptions: PropTypes.array, |
16 | disabledHours: PropTypes.array, | ||
17 | disabledMinutes: PropTypes.array, | ||
18 | disabledSeconds: PropTypes.array, | ||
16 | onChange: PropTypes.func, | 19 | onChange: PropTypes.func, |
17 | onClear: PropTypes.func, | 20 | onClear: PropTypes.func, |
18 | onEsc: PropTypes.func, | 21 | onEsc: PropTypes.func, |
@@ -54,7 +57,7 @@ const Header = React.createClass({ | |||
54 | str, | 57 | str, |
55 | }); | 58 | }); |
56 | let value = null; | 59 | let value = null; |
57 | const {formatter, gregorianCalendarLocale, hourOptions, minuteOptions, secondOptions, onChange, allowEmpty} = this.props; | 60 | const {formatter, gregorianCalendarLocale, hourOptions, minuteOptions, secondOptions, disabledHours, disabledMinutes, disabledSeconds, onChange, allowEmpty} = this.props; |
58 | 61 | ||
59 | if (str) { | 62 | if (str) { |
60 | const originalValue = this.props.value; | 63 | const originalValue = this.props.value; |
@@ -71,6 +74,7 @@ const Header = React.createClass({ | |||
71 | } | 74 | } |
72 | 75 | ||
73 | if (value) { | 76 | if (value) { |
77 | // if time value not allowed, response warning. | ||
74 | if ( | 78 | if ( |
75 | hourOptions.indexOf(value.getHourOfDay()) < 0 || | 79 | hourOptions.indexOf(value.getHourOfDay()) < 0 || |
76 | minuteOptions.indexOf(value.getMinutes()) < 0 || | 80 | minuteOptions.indexOf(value.getMinutes()) < 0 || |
@@ -82,6 +86,18 @@ const Header = React.createClass({ | |||
82 | return; | 86 | return; |
83 | } | 87 | } |
84 | 88 | ||
89 | // if time value is disabled, response warning. | ||
90 | if ( | ||
91 | disabledHours.indexOf(value.getHourOfDay()) >= 0 || | ||
92 | disabledMinutes.indexOf(value.getMinutes()) >= 0 || | ||
93 | disabledSeconds.indexOf(value.getSeconds()) >= 0 | ||
94 | ) { | ||
95 | this.setState({ | ||
96 | invalid: true, | ||
97 | }); | ||
98 | return; | ||
99 | } | ||
100 | |||
85 | if (originalValue && value) { | 101 | if (originalValue && value) { |
86 | if ( | 102 | if ( |
87 | originalValue.getHourOfDay() !== value.getHourOfDay() || | 103 | originalValue.getHourOfDay() !== value.getHourOfDay() || |