From 518b852e8bd9c50a6c5c7e84cddecb5c94ebb5b6 Mon Sep 17 00:00:00 2001
From: MG12 <wuzhao.mail@gmail.com>
Date: Sat, 12 Dec 2015 20:34:00 +0800
Subject: add new options about disabled time

---
 src/module/Header.jsx | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

(limited to 'src/module/Header.jsx')

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({
     hourOptions: PropTypes.array,
     minuteOptions: PropTypes.array,
     secondOptions: PropTypes.array,
+    disabledHours: PropTypes.array,
+    disabledMinutes: PropTypes.array,
+    disabledSeconds: PropTypes.array,
     onChange: PropTypes.func,
     onClear: PropTypes.func,
     onEsc: PropTypes.func,
@@ -54,7 +57,7 @@ const Header = React.createClass({
       str,
     });
     let value = null;
-    const {formatter, gregorianCalendarLocale, hourOptions, minuteOptions, secondOptions, onChange, allowEmpty} = this.props;
+    const {formatter, gregorianCalendarLocale, hourOptions, minuteOptions, secondOptions, disabledHours, disabledMinutes, disabledSeconds, onChange, allowEmpty} = this.props;
 
     if (str) {
       const originalValue = this.props.value;
@@ -71,6 +74,7 @@ const Header = React.createClass({
       }
 
       if (value) {
+        // if time value not allowed, response warning.
         if (
           hourOptions.indexOf(value.getHourOfDay()) < 0 ||
           minuteOptions.indexOf(value.getMinutes()) < 0 ||
@@ -82,6 +86,18 @@ const Header = React.createClass({
           return;
         }
 
+        // if time value is disabled, response warning.
+        if (
+          disabledHours.indexOf(value.getHourOfDay()) >= 0 ||
+          disabledMinutes.indexOf(value.getMinutes()) >= 0 ||
+          disabledSeconds.indexOf(value.getSeconds()) >= 0
+        ) {
+          this.setState({
+            invalid: true,
+          });
+          return;
+        }
+
         if (originalValue && value) {
           if (
             originalValue.getHourOfDay() !== value.getHourOfDay() ||
-- 
cgit v1.2.3

