marquex
2016-04-19 92a2c6816897ef287584aaa67cee2904eb31be22
Month and year pickers don't show the time in input anylonger.
7 files modified
56 ■■■■■ changed files
CHANGELOG.md 3 ●●●●● patch | view | raw | blame | history
DateTime.js 23 ●●●●● patch | view | raw | blame | history
package.json 3 ●●●● patch | view | raw | blame | history
src/DaysView.js 1 ●●●● patch | view | raw | blame | history
src/MonthsView.js 2 ●●● patch | view | raw | blame | history
src/YearsView.js 2 ●●● patch | view | raw | blame | history
tests/datetime-spec.js 22 ●●●● patch | view | raw | blame | history
CHANGELOG.md
@@ -1,5 +1,8 @@
Changelog
=========
## 2.2.0
* The picker can be used as a month or year picker just giving a format date without days/months
* Updates test suite
## 2.1.0
* Fixed rdtActive not getting set.
DateTime.js
@@ -43,7 +43,6 @@
        return {
            className: '',
            defaultValue: '',
            viewMode: 'days',
            inputProps: {},
            input: true,
            onFocus: nof,
@@ -61,7 +60,7 @@
        if( state.open == undefined )
            state.open = !this.props.input;
        state.currentView = this.props.dateFormat ? this.props.viewMode : 'time';
        state.currentView = this.props.dateFormat ? (this.props.viewMode || state.updateOn || 'days') : 'time';
        return state;
    },
@@ -98,13 +97,17 @@
    },
    getUpdateOn: function(formats){
        if(formats.datetime.indexOf("D") != -1){
            return "date";
        }else if(formats.datetime.indexOf("M") != -1){
            return "month";
        }else if(formats.datetime.indexOf("Y") != -1){
            return "year";
        if( formats.date.match(/[lLD]/) ){
            return "days";
        }
        else if( formats.date.indexOf("M") != -1 ){
            return "months";
        }
        else if( formats.date.indexOf("Y") != -1 ){
            return "years";
        }
        return 'days';
    },
    getFormats: function( props ){
@@ -118,6 +121,10 @@
        if( formats.date === true ){
            formats.date = locale.longDateFormat('L');
        }
        else if( this.getUpdateOn(formats) !== 'days' ){
            formats.time = '';
        }
        if( formats.time === true ){
            formats.time = locale.longDateFormat('LT');
        }
package.json
@@ -1,6 +1,6 @@
{
  "name": "react-datetime",
  "version": "2.1.0",
  "version": "2.2.0",
  "description": "A lightweight but complete datetime picker React.js component.",
  "homepage": "https://github.com/arqex/react-datetime",
  "repository": {
@@ -36,6 +36,7 @@
    "jsdom": "^7.0.2",
    "mocha": "^2.2.5",
    "react": ">=0.13",
    "react-addons-test-utils": "^0.14.8",
    "react-tools": "^0.13.2",
    "webpack": "^1.5.1",
    "webpack-dev-server": "^1.7.0"
src/DaysView.js
@@ -121,6 +121,7 @@
            return '';
        var date = this.props.selectedDate || this.props.viewDate;
        return DOM.tfoot({ key: 'tf'},
            DOM.tr({},
                DOM.td({ onClick: this.props.showView('time'), colSpan: 7, className: 'rdtTimeToggle'}, date.format( this.props.timeFormat ))
src/MonthsView.js
@@ -37,7 +37,7 @@
                key: i,
                'data-value': i,
                className: classes,
                onClick: this.props.updateOn=="month"?this.updateSelectedMonth:this.props.setDate('month')
                onClick: this.props.updateOn=="months"? this.updateSelectedMonth : this.props.setDate('month')
            };
            months.push( renderer( props, i, year, date && date.clone() ));
src/YearsView.js
@@ -38,7 +38,7 @@
                key: year,
                'data-value': year,
                className: classes,
                onClick: this.props.updateOn=="year"?this.updateSelectedYear:this.props.setDate('year')
                onClick: this.props.updateOn=="years" ? this.updateSelectedYear : this.props.setDate('year')
            };
            years.push( renderer( props, year, selectedDate && selectedDate.clone() ));
tests/datetime-spec.js
@@ -4,14 +4,13 @@
// Needs to be global to work in Travis CI
React = require('react/addons');
React = require('react');
ReactDOM = require('react-dom');
var ReactAddons = require('react/addons'),
    Utils = React.addons.TestUtils,
    Datetime = require('../DateTime'),
var Datetime = require('../DateTime'),
    assert = require('assert'),
    moment = require('moment')
    moment = require('moment'),
    TestUtils = require('react-addons-test-utils')
;
var createDatetime = function( props ){
@@ -31,7 +30,7 @@
   element.dispatchEvent( ev );
};
var ev = React.addons.TestUtils.Simulate;
var ev = TestUtils.Simulate;
var dt = {
    dt: function(){
        return document.getElementById('root').children[0];
@@ -106,6 +105,7 @@
        assert.equal( component.children[0].tagName , 'DIV' );
    });
    it( 'Date value', function(){
        var component = createDatetime({ value: date }),
            input = component.children[0]
@@ -166,7 +166,6 @@
        // There must not be a date toggle
        assert.equal( view.querySelectorAll('thead').length, 0);
    });
    it( 'timeFormat', function(){
        var format = 'HH:mm:ss:SSS',
            component = createDatetime({ value: date, timeFormat: format }),
@@ -558,7 +557,7 @@
        assert.equal( dt.input().value, 'luis' );
        dt.input().value = strDate;
        Utils.Simulate.change( dt.input() );
        ev.change( dt.input() );
    });
    it( 'delete input value', function( done ){
@@ -567,7 +566,7 @@
            done();
        }});
        dt.input().value = '';
        Utils.Simulate.change( dt.input() );
        ev.change( dt.input() );
    });
    it( 'strictParsing=true', function( done ){
@@ -578,7 +577,7 @@
        }});
        dt.input().value = invalidStrDate;
        Utils.Simulate.change( dt.input() );
        ev.change( dt.input() );
    });
    it( 'strictParsing=false', function( done ){
@@ -589,7 +588,6 @@
        }});
        dt.input().value = invalidStrDate;
        Utils.Simulate.change( dt.input() );
        ev.change( dt.input() );
    });
});