Coder Social home page Coder Social logo

skratchdot / react-bootstrap-daterangepicker Goto Github PK

View Code? Open in Web Editor NEW
476.0 476.0 205.0 13.45 MB

A date/time picker for react (using bootstrap). This is a react wrapper around the bootstrap-daterangepicker project.

Home Page: http://projects.skratchdot.com/react-bootstrap-daterangepicker/

License: Other

JavaScript 89.32% TypeScript 10.68%

react-bootstrap-daterangepicker's Introduction

react-bootstrap-daterangepicker

NPM version Build Status Code Climate Coverage Status

NPM

🚨 Deprecation Notice 🚨

I put this project on github because I used it briefly for a project back in 2014. I haven't used it for years, and have recommended looking for a "pure react" date picker library. I might continue to merge small PRs, but will not be giving this library much/any support. I recommend using one of the other react date picker libraries listed below.

Description

A date/time picker for react (using bootstrap). This is a react wrapper around an existing jQuery/bootstrap library (it is not a pure react port):

bootstrap-daterangepicker

Getting Started

  1. Install the needed peer dependencies: npm install --save bootstrap-daterangepicker react jquery moment

  2. Install the module with: npm install --save react-bootstrap-daterangepicker

  3. Include the bootstrap@4 css and fonts in your project. (aka import 'bootstrap/dist/css/bootstrap.css';)

  4. Include the bootstrap-daterangepicker css in your project. (aka import 'bootstrap-daterangepicker/daterangepicker.css';)

  5. This is a commonjs library. You will need a tool like browserify/webpack/etc to build your code.

import React, { Component } from 'react';
import DateRangePicker from 'react-bootstrap-daterangepicker';
// you will need the css that comes with bootstrap@3. if you are using
// a tool like webpack, you can do the following:
import 'bootstrap/dist/css/bootstrap.css';
// you will also need the css that comes with bootstrap-daterangepicker
import 'bootstrap-daterangepicker/daterangepicker.css';

class MyComponent {
  render() {
    return (
      <DateRangePicker
        initialSettings={{ startDate: '1/1/2014', endDate: '3/1/2014' }}
      >
        <button>Click Me To Open Picker!</button>
      </DateRangePicker>
    );
  }
}

Documentation

For in depth documentation, see the original bootstrap-daterangepicker project page.

You can pass all the settings from the original plugin to the initialSettings prop:

  • <input>, alwaysShowCalendars, applyButtonClasses, applyClass, autoApply, autoUpdateInput, buttonClasses, cancelButtonClasses, cancelClass, dateLimit, drops, endDate, isCustomDate, isInvalidDate, linkedCalendars, locale, maxDate, maxSpan, maxYear, minDate, minYear, moment, opens, parentEl, ranges, showCustomRangeLabel, showDropdowns, showISOWeekNumbers, showWeekNumbers, singleDatePicker, startDate, template, timePicker, timePicker24Hour, timePickerIncrement, timePickerSeconds

You can listen to the following 8 events:

  • onShow: callback(event, picker) thrown when the widget is shown
  • onHide: callback(event, picker) thrown when the widget is hidden
  • onShowCalendar: callback(event, picker) thrown when the calendar is shown
  • onHideCalendar: callback(event, picker) thrown when the calendar is hidden
  • onApply: callback(event, picker) thrown when the apply button is clicked
  • onCancel: callback(event, picker) thrown when the cancel button is clicked
  • onEvent: callback(event, picker) thrown when any of the 6 events above are triggered
  • onCallback: callback(start, end, label) thrown when the start/end dates change

You MUST pass a single child element to the <DateRangePicker /> component- and it MUST be a DOM element. Passing custom react components is not currently supported b/c this lib needs a single dom node to initialize.

NOTE: This component should be used as an Uncontrolled Component. If you try to control the value of your child <input />, then you will probably encounter issues.

There are 2 methods from the upstream lib that can be called: setStartDate and setEndDate, but you need to use refs when doing so. Please view the storybook for an example of this.

Examples

For more usage examples, please view the storybook:
https://projects.skratchdot.com/react-bootstrap-daterangepicker/

Simple button example

<DateRangePicker>
  <button type="button" className="btn btn-primary">
    click to open
  </button>
</DateRangePicker>

Simple input example

<DateRangePicker>
  <input type="text" className="form-control" />
</DateRangePicker>

Initialize with a startDate and endDate

<DateRangePicker
  initialSettings={{ startDate: '01/01/2020', endDate: '01/15/2020' }}
>
  <input type="text" className="form-control" />
</DateRangePicker>

Example event handler:

class SomeReactComponent extends React.Component {
  handleEvent(event, picker) {
    console.log(picker.startDate);
  }
  handleCallback(start, end, label) {
    console.log(start, end, label);
  }
  render() {
    return (
      <DateRangePicker onEvent={this.handleEvent} onCallback={this.handleCallback}>
        <input />
      </DateRangePicker>;
  }
}

Release Notes

Release notes can be found in the Changelog.

Links

Other React Date Pickers

NOTE: Please submit a PR if there are other date pickers you can recommend

License

Copyright (c) 2014 skratchdot
Uses the original bootstrap-daterangepicker license.

react-bootstrap-daterangepicker's People

Contributors

atkawa7 avatar barbalex avatar carlsagan21 avatar codeos avatar danhab99 avatar diego-betto avatar eyepulp avatar flakekun avatar justinsisley avatar mistadikay avatar nicubarbaros avatar oliger avatar paulsender avatar peter-mouland avatar pierr avatar rehanumar avatar rmdort avatar rudolph-miller avatar sbellity avatar skratchdot avatar spinloop avatar thevikas avatar timc13 avatar yashksagar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-bootstrap-daterangepicker's Issues

daterangepicker does not render

Hello and thanks for porting this for react!

I am having an issue with it - and cannot get it to render in my React APP.

First, I will show you my code:

My component - Register.js (A registration form)

/**
 * @jsx React.DOM
 */

'use strict';

var React = require('react/addons');
var Router = require('react-router');


var TextInput = require('../util/TextInput');
var Selector = require('../util/Selector');
var PasswordInput = require('../PasswordInput');
var Button = require('react-bootstrap/Button');
var Input = require('react-bootstrap/Input');

var UserActions = require('../../actions/UserActions');

var Countries = require('../../constants/Countries.js');
var RightsOrganisations = require('../../constants/RightsOrganisations.js');

var DateRangePicker = require('react-bootstrap-daterangepicker');


var Register = React.createClass({

    getInitialState: function() {
        return {stageName: '',
                firstName: '',
                lastName: '',
                emailAddress: '',
                password: '',
                passwordValid: false,
                isBand: false,
                dateOfBirth: '',
                country: '',
                gender: '',
                rightsOrganisation: '',
                promotionCode: ''};
        },

    _onPasswordValid: function(isValid) {
        this.setState({passwordValid: isValid});
    },

    _onPasswordChange: function(pass) {
        this.setState({password: pass});
    },

    _onSubmit: function() {
        var s = this.state;
        UserActions.register(s.stageName, s.firstName, s.lastName, s.emailAddress,
                             s.password, s.isBand, s.dateOfBirth, s.country, s.gender,
                             s.rightsOrganisation, s.promotionCode);
        Router.transitionTo('/registering');
    },

    handleEvent: function (event, picker) {
        console.log(picker.startDate);
    },

    render: function () {
        return (
            <div className='signUp-form'>
                <h1>Your Information Hello</h1>
                <form className='form-horizontal' id="wwb_signup_form">
                <div className='form-fields'>
                    <div className='form-group clearfix'>
                        <TextInput label="User name" id="stagename"
                                  labelClass='control-label' inputClass='form-control'
                                  value={this.state.stageName}
                                  onSave={function(v) {this.setState({stageName: v})}.bind(this)} />
                    </div>
                    <div className='form-group clearfix'>
                        <TextInput label="First name" id="firstname"
                                  labelClass='control-label' inputClass='form-control'
                                  value={this.state.firstName}
                                  onSave={function(v) {
                                      this.setState({firstName:v})
                                  }.bind(this)} />
                    </div>
                    <div className='form-group clearfix'>
                        <TextInput label="Last name" id="lastname"
                                  labelClass='control-label' inputClass='form-control'
                                  value={this.state.lastName}
                                  onSave={function(v) {
                                      this.setState({lastName:v})
                                  }.bind(this)} />
                    </div>
                    <div className='form-group clearfix'>
                        <TextInput label="Email" id="emailaddress"
                                  labelClass='control-label' inputClass='form-control'
                                  value={this.state.emailAddress}
                                  onSave={function(v) {
                                      this.setState({emailAddress:v})
                                  }.bind(this)} />
                    </div>
                    <div className='form-group clearfix'>
                        <PasswordInput passLabel="Password" 
                               passRepeatLabel='Confirm Password'
                               id="password"
                                  className='form-control'
                                  labelClass='control-label' inputClass='form-control'
                                  value={this.state.password}
                                  onPasswordChange={this._onPasswordChange}
                                  onPasswordValid={this._onPasswordValid} />
                    </div>
                    <div className='form-group clearfix'>
                        <Input label="Band"
                               id="band"
                               type="checkbox"
                               className='form-control'
                               value={this.state.isBand}
                               onChange={function(e) {
                                   this.setState({isBand:e.target.value})
                               }.bind(this)}/>
                    </div>
                    <div className=''>
                      <DateRangePicker id='mypicker' format="YYYY-MM-DD" 
                                       startDate="1900-01-01" 
                                       endDate="2014-12-31" 
                                       singleDatePicker="True"
                                       onEvent={this.handleEvent} />
                    </div>
                    <div className='form-group clearfix'>
                        <Selector label="Gender" id="gender" options={{'Please select': '', 'Male': 'M', 'Female': 'F'}} 
                                  value={this.state.country}
                                  onChange={function(v) {
                                      this.setState({gender:v})
                                  }.bind(this)}/>
                    </div>
                    <div className='form-group clearfix'>
                        <Selector label="Country" id="country" options={Countries} 
                                  value={this.state.country}
                                  onChange={function(v) {
                                      this.setState({country:v})
                                  }.bind(this)}/>
                    </div>
                    <div className='form-group clearfix'>
                        <Selector label="Rights Organisation" id="rights-organisation"
                             options={RightsOrganisations}
                             value={this.state.rightsOrganisation}
                             onChange={function(v) {
                                 this.setState({rightsOrganisation:v})
                             }.bind(this)}/>
                    </div>
                    <div className='form-group clearfix'>
                        <TextInput label="Promotion code" id="promotioncode"
                                  labelClass='control-label' inputClass='form-control'
                                  value={this.state.promotionCode}
                                  onSave={function(v) {
                                      this.setState({promotionCode:v})
                                  }.bind(this)}/>
                    </div>
                    </div>
                <div className="form-group">
                    <div className="inputCnt">
                        <Button onClick={this._onSubmit} className="btn btn-default">Create Account</Button>
                    </div>
                </div>
                </form>
            </div>
        );
    }
});

module.exports = Register;

There are no compilation errors or warnings and no errors when I inspect element in Chrome.
I can see the object mypicker in the DOM

What I do see when I examine with the React tab is that size seems to be 0 - see attached screenshots.

screen shot 2014-08-28 at 16 10 56

Could you give me any idea what I may be doing wrong - that would be much appreciated.

thanks
Bernadette

minDate breaks

I recently upgraded my version of this module and found that when I provide a value to the minDate attribute, I get the following error in the console:

"moment.js:113 Uncaught TypeError: Array.prototype.some called on null or undefined"

Any suggestions?

Thanks in advanced!

Small housekeeping items? (Documentation and console.log)

Love the component. Two small things:

Documentation Update

The readme usage says to use the following:

  • <DateRangePicker startDate="1/1/2014" endDate="3/1/2014">

I found I had to use this instead:

  • <DateRangePicker startDate={moment("2014-04-23T09:54:51")} endDate={moment("2014-08-23T09:54:51")}>

Index.js Has The Following Line

  • console.log(this.$picker.data('daterangepicker'));

Was that perhaps left over from development?

Uncaught TypeError: this.parentEl.is is not a function

This error occurs in daterangepicker.js:991 (v 2.1.13, downloaded, not installed via npm).

The props are: (except className and onEvent it's right from daterangepicker generator)

parentEl: 'body'
timePicker: true                                                    
timePicker24Hour: true                                              
startDate: @props.StartTime                                         
endDate: @props.EndTime                                             
opens: "center"                                                     
drops: "up"                                                         
onEvent: @_onDateChange                                             
className: 'btn btn-primary' 

The case is that this.parentEl == 'body' instead of $('body'). Putting this.parentEl = $(this.parentEl) before line 991 solves the problem. Also not using parentEl option solves the problem. Don't know if it's problem in react daterangepicker or daterangepicker.js.

How to enable the scroll bar in a modal?

if I have many content in the modal body, I can enable the browser's h scroll bar, but is not good-look. Could we enable the scroill bar for the modal? how to do it ? by what property? or add a panel to modal -body?

Thank you!


const myModal = React.createClass({
render: function() {
return (
<Modal {...this.props} title={title} animation={false} >


Many Contest
Many Contest
...many many label....


<Button bsStyle='primary' onClick={ this.props.onRequestHide}>Done


);
}
});

Version without jQuery

Why

One of the things makes ReactJS powerful is virtualDOM, which React will handle all the DOM manipulation and decide if a change should be applied or not. Think about it, both Angular and Ember are going to put virtualDOM concept into their coming version 2.0.

In that sense, jQuery should not be used in ReactJS as ReactJS doesn't encourage people to do any direct DOM modification and it can be done without jQuery.

Template in options

Could you add template to the options? It is not documented in original plugin but you can set it.

Cannot set property 'daterangepicker' of undefined

I am using webpack to bundle my app. I get this error right after webpack says the bundle is VALID.

/home/aaron/Repos/smart-spray-portal/node_modules/react-bootstrap-daterangepicker/node_modules/bootstrap-daterangepicker/daterangepicker.js:1483
    $.fn.daterangepicker = function(options, callback) {
                         ^

TypeError: Cannot set property 'daterangepicker' of undefined
    at /home/aaron/Repos/smart-spray-portal/node_modules/react-bootstrap-daterangepicker/node_modules/bootstrap-daterangepicker/daterangepicker.js:1483:26
    at cb.parentEl (/home/aaron/Repos/smart-spray-portal/node_modules/react-bootstrap-daterangepicker/node_modules/bootstrap-daterangepicker/daterangepicker.js:28:5)
    at Object.<anonymous> (/home/aaron/Repos/smart-spray-portal/node_modules/react-bootstrap-daterangepicker/node_modules/bootstrap-daterangepicker/daterangepicker.js:35:2)
    at Module._compile (module.js:435:26)
    at Module._extensions..js (module.js:442:10)
    at Object.require.extensions.(anonymous function) [as .js] (/home/aaron/Repos/smart-spray-portal/node_modules/babel-core/lib/api/register/node.js:214:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)

I am not certain where to look for an answer to this issue. I don't believe that webpack is the problem, since it bundles fine. I am looking at my babel setup to see if there is anything missing there. Any suggestions from anyone?

Can not be used in the case of jquery 2.1.4

Problem Description:
When I was in the case of using jquery 2.1.4, click on the components, but can not be displayed anything. I navigate to a specific error:
$this.$picker = $ (this.refs.picker);
when I will replace this code into
$this.$picker = $(React.findDOMNode(this.refs.picker));
it work!

error when pass props parentEl to string "#some-div-id"

the props of parentEl will overlap the parentEl member of DateRangePicker to string when 'setOptionsFromProps' is called.
When DateRangePicker.clickDate is called , the error occurs at DateRangePicker.move function "if (!this.parentEl.is('body')) ", because of the 'this.parentEl' is overlap with a String

Uncaught Error: Cannot find module 'react-bootstrap-daterangepicker'

Fist, installation is finished with this warn: npm WARN install: UNMET PEER DEPENDENCY:

$ npm install --save react-bootstrap-daterangepicker
npm WARN install Couldn't install optional dependency: Unsupported
[email protected] node_modules\moment -> node_modules\bootstrap-daterangepicker\node_modules\moment
[email protected] c:\Users\user\sbox\node\app
├── UNMET PEER DEPENDENCY [email protected]
└── [email protected]

npm WARN EPEERINVALID [email protected] requires a peer of jquery@^1.11.3 but none was installed.

Then, after installation and require-ing react-bootstrap-daterangepicker in a module with my app's components, an error was thrown in a browser console:
Uncaught Error: Cannot find module 'react-bootstrap-daterangepicker'

My components are compiled with Browserify all right without react-bootstrap-daterangepicker. So it is not a build issue.

Why this error? How to solve it?

Versions of packages in my package.json

    "jquery": "^2.1.4",
    "moment": "^2.10.6",
    "react": "^0.14.3"

How to close a modal by a funciton

I have a modal, there is done button, when clicking the button, I'll do some bussiness process, then close the modal, but I can't close by calling like this

const myModal = React.createClass({
render: function() {
return (
<Modal {...this.props} title={title} animation={false} id="ModelID" >


....


Done


);
},
checkDone: function() {
var checkboxList = document.getElementsByName("something");
var loading_dialog = document.getElementById("ModelID");
var myData = [];
for(var i = 0; i < checkboxList.length; i++) {
if (checkboxList[i].checked) {
myData.push(checkboxList[i].id);
}
}

    this.props.onRequestHide;

}

});

when I call $(this.getDOMNode()).modal("hide");, it still can't work.

How do we call the onRequestHide in my self-defining function?

I know when I do like this , it can close the modal. Thank you very much!
closed

Disable calendar

I have implemented react-bootstrap-daterangepicker component in following way:

var React = require('react');
var Bs = require('react-bootstrap');
var DateTimeField = require('react-bootstrap-daterangepicker');
var moment = require('moment');
const InnerGlyphicon = <Bs.Glyphicon glyph='calendar' />;

var DateField = React.createClass({

    getInitialState: function () {
        return {
            ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'This Week': [moment().startOf('isoWeek'),moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            },
            startDate: moment(this.props.startDate, 'DD/MM/YYYY'),
            endDate: moment(this.props.endDate, 'DD/MM/YYYY')
        };
    },

    render : function (){
       return (
           <div>
               <DateTimeField className={'datePicker'}
                              onEvent={this.handleDateEvents}
                              dateTime={moment().format('DD/MM/YYYY')}
                              startDate={this.state.startDate}
                              endDate={this.state.endDate}
                              minDate={this.props.minDate}
                              maxDate={this.props.maxDate}
                              ranges={this.state.ranges}
                              timePicker={true}
                              timePicker24Hour={true}
                              timePickerIncrement={1}
                              showWeekNumbers={true}
                              onShow={this.handleOnShow}
                              type={'datetimerange'}
                   >
                   <Bs.Input type='text' placeholder={moment(this.state.startDate).format('DD/MM/YYYY') + ' - ' + moment(this.state.endDate).format('DD/MM/YYYY')} addonAfter={InnerGlyphicon} />
               </DateTimeField>

           </div>

       );
    },

    /* This function updates Bs.Input date range according to  selected date*/
    handleDateEvents: function (event, picker) {


        if(event.type==='apply'){
            this.setState({
                startDate: picker.startDate,
                endDate:picker.endDate
            });
        }
       this.props.handleDateEvents(event,picker);
    }
});

This component is showing calendar like (Today, Yesterday, Last 7 Days etc.) no matter what i choose:

459be93c19eb12a31abca9d77c59e37d

Instead of it i want, that calendar shows only on "Custom range", like in this example datepicker:

aaa

I can't figure out why dateTime doesn't act like in demo. Is there some config needed for it, or its just a bug or maybe i am doing something wrong?

How Calendar is Displayed

For Some reason the calendar displays when you click the button as below:
DateRangePicker startDate={moment('1/1/2014')} endDate={moment('3/1/2014')}
div Click Me To Open Picker! div
DateRangePicker

But if you remove the " div Click Me To Open Picker! div" which leaves
DateRangePicker startDate={moment('1/1/2014')} endDate={moment('3/1/2014')}
DateRangePicker

And re render/refresh the page, the calendar doesn't show at all. Is this a common bug? Is there a way to display the full calendar upon loading the page. I am new to this tool. It's really awesome and I would love to use it. My goal is to display the calendar upon loading the page. When editing the "daterangepicker.css" file, and adding "display: inline-block" in the .daterangepicker function, I get a blank calendar and nothing shows. Can someone help me with this? It seems as if a button in the div only fires the full calendar. Is this true

Missing documentation for "timeZone" parameter

In the README I can see a reference to a timeZone parameter that can be used with the component however I can't seem to find any reference to this parameter in the original bootstrap-daterangepicker docs so I was wandering how exactly does it work?

Error with React 0.14 + Changing Properties

I am seeing the dropdowns fail to open after anything changes DateRangePicker's properties.

How to reproduce a date picker to anything with changing inputs. In render use something like:

<DateRangePicker minDate={range.min} maxDate={range.max}
                 startDate={currentFilter.min} endDate={currentFilter.max}
                 showDropdowns={true}>
    <p>Showing from: {this.formatDate(currentFilter.min)} to {this.formatDate(currentFilter.max)} </p>
</DateRangePicker>

This will work correctly on the initial render, but after any change the following error appears after clicking on the text.

Uncaught TypeError: this.startDate.clone is not a functionDateRangePicker.show @ daterangepicker.js:1063DateRangePicker.toggle @ daterangepicker.js:1100n.isFunction.f @ jquery-2.1.4.min.js:2n.event.dispatch @ jquery-2.1.4.min.js:3r.handle @ jquery-2.1.4.min.js:3

Using [email protected] with [email protected]

minDate alongside singleDatePicker option

I'm using the singleDatePicker: true option and I noticed that the available dates to choose from started on my current day. So I added the minDate option with a date very far back and it didn't seem to change anything. I saw someone mention this same bug on the non-react version, is this potentially related?

https://github.com/dangrossman/bootstrap-daterangepicker/issues/432

Or maybe there's a nuance I'm not seeing to get the minDate working correctly with the singleDatePicker option? Ideally, I'd like to allow any date in the past.

jQuery?

I was saddened by this when I did the NPM install and automatically made it a no go. Any way to get this kind of functionality without jQ anyone do a react only fork of this? I know this is just a port of the old jQ plugin, so I guess that may be asking for a lot, but it doesn't seem worth importing jQ for just this when I already have react, react-router, and react-bootstrap weighing me down.

Either way, thanks for your hard work, wish I could actually use this.

Uncaught TypeError: $this.$picker.daterangepicker is not a function

Hi,

I just install this plugin, and i can't get rid off this error:
Uncaught TypeError: $this.$picker.daterangepicker is not a function

my setup is :
"dependencies": {
"bootstrap": "^3.3.5",
"history": "^1.12.5",
"intl": "^1.0.1",
"jquery": "^2.1.4",
"jquery-ui": "^1.10.5",
"moment": "^2.10.6",
"react": "^0.14.0",
"react-addons": "^0.9.0",
"react-addons-test-utils": "^0.14.0",
"react-addons-update": "^0.14.0",
"react-bootstrap": "^0.27.2",
"react-bootstrap-daterangepicker": "^1.0.2",
"react-dom": "^0.14.0",
"react-gravatar": "^2.1.0",
"react-intl": "^1.2.1",
"react-router": "^1.0.0-rc3"
},

'use strict'

var React = require('react');
var moment = require('moment');
var DateRangePicker = require('react-bootstrap-daterangepicker');

var DateRange = React.createClass({
getInitialState: function () {
return {
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
startDate: moment().subtract(29, 'days'),
endDate: moment()
};
},
handleEvent: function (event, picker) {
this.setState({
startDate: picker.startDate,
endDate: picker.endDate
});
},
render: function() {
var start = this.state.startDate.format('YYYY-MM-DD');
var end = this.state.endDate.format('YYYY-MM-DD');
var label = start + ' - ' + end;
if (start === end) {
label = start;
}
return (



<button className="btn btn-default selected-date-range-btn" style={{width:'100%'}}>

icon



{label}






);
}
});
module.exports = DateRange;

can someone tell me what wrong, thanks.

have an error with new version

with dependencies:
"jquery": "~2.1.4",
"react": "^0.14.0",
"react-bootstrap-daterangepicker": "^1.0.1",
have an error:
"Uncaught TypeError: $this.$picker.daterangepicker is not a function"

with old version:
"jquery": "~2.1.4",
"react": "^0.14.0",
"react-bootstrap-daterangepicker": "^0.6.0",
all working fine, do you have any idea how to fix that?

Uncaught TypeError: Cannot set property 'daterangepicker' of undefined

The following line in daterangepicker.js causing an error.

   root.daterangepicker = factory(root, exports, momentjs, $);

My component looks like this

var React = require('react');
var moment = require('moment');
var $ = require('jquery');
var DateRangePicker = require('react-bootstrap-daterangepicker');
var CustomDatePickerComponent = React.createClass({
    render: function () {
        return (
            <div>
            <DateRangePicker startDate={moment('1/1/2014')} endDate={moment('3/1/2014')}>
                <div>Click Me To Open Picker!</div>
            </DateRangePicker>
            </div>
        );
    }
});
module.exports = CustomDatePickerComponent;

How to build a "dist" version

I have the very unfortunate need of using this in a project that does NOT have browerify or webpack (pause for horror).

Normally i'd npm build etc, but i'm not 100% sure with gulp. the "demo" task seems like it does some of this work (but way too much other work)

Thoughts :)?

Question: Use as content of modal body?

Is it possible to open a bootstrap modal (I'm using react-bootstrap) and show the picker as the body of the modal? The layout would remain the same, except the Apply and Cancel buttons would be moved to the modal footer. Is this possible without modifying the component?

Apologies if this is an obvious thing to do, I'm a server-side hacker and my JS/React skills are quite raw! I've had a look round the docs (yours and original) and can't see any obvious option.

partial param in locale case error

I'm not sure why you call setOptionsFromProps in render.
I found that if locale just has part param, render would failed.

<DateRangePicker startDate={this.state.startDate}
            endDate={this.state.endDate}
            ranges={this.state.ranges}
            opens='left'
            onEvent={this.handleEvent}
            locale={{
              applyLabel: "ok",
              customRangeLabel: "user define"}}> </DateRangePicker>

It seems because the picker's locale attribute is replaced by locale which I define.

if ($this.$picker) {
            if (currentOptions) {
                keys.forEach(function (key) {
                    $this.$picker.data('daterangepicker')[key] = currentOptions[key];//????? should it use object-assign when key's value is an object?
                });
            }
        }

I removed the calling of setOptionsFromProps in render, it worked.
I think the custom options just need transmit to daterangepicker once, which already done in componentDidMount。
Otherwise, use Object.assign to copy partial params.

Deprecation warning: moment construction falls back to js Date

Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to moment/moment#1407 for more info.
Arguments: [object Object]
Error
at Function.createFromInputFallback (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:123422:106)
at configFromInput (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:124838:33)
at prepareConfig (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:124809:14)
at createFromConfig (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:124776:45)
at createLocalOrUTC (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:124858:17)
at local__createLocal (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:124862:17)
at Moment.isAfter (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:125360:53)
at DateRangePicker.renderTimePicker (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:175502:35)
at DateRangePicker.updateView (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:175158:23)
at DateRangePicker.show (http://localhost:3001/dist/main-a211bc16e0db174aed08.js:175724:19)

Typing dates in custom ranges are too sensitive

When typing in the right input box for a custom range, the right box updates too much creating invalid ranges and losing the right value.

screen_shot_2015-09-06_at_4 12 29_pm_360

Locally, I have changed:

.on('keyup.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this)) 
.on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.updateFormInputs, this));

to this:

.on('blur.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this))
// .on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.updateFormInputs, this));

so that the left value only changes when the left element loses focus/blurs and doesn't get wiped out on the change event.

I thinking this is a better approach, but not sure if I am missing any use cases.

Missing alwaysShowCalendars in ./lib/get-options.js

I tried to appy an option called 'alwaysShowCalendars'. It supposed to work exactly what it is called - when range option is applied, to make calendar visible.

But in react-bootstrap-daterangepicker the option was not working. So I changed './lib/get-options.js' to recognize it, and it worked perfectly.

So plz check, and I'm gonna make a pull request.

Option props not being set properly on render

I want to have the week start on Monday, so I'm rendering the daterpicker like so:

                <DateRangePicker onEvent={this.changeValue} startDate={start} endDate={end}
                                 opens="left" ranges={ranges} format="DD/MM/YYYY" locale={{firstDay: 1}}>
                    <div className="button selected-date-range-btn">
                        <i className="fa fa-calendar pull-left" />
                        <span className="pull-left">{label}</span>
                        <i className="fa fa-caret-down pull-right" />
                    </div>
                </DateRangePicker>

In 0.2.6, this works fine. However in 0.2.7 and all later version, it does not, because of the change to setOptionsFromProps(). The constructor for the underlying widget does some smart merging of the options object with defaults; when the constructor finishes this.locale ends up looking like this:

{
   "format":"MM/DD/YYYY",
   "separator":" - ",
   "applyLabel":"Apply",
   "cancelLabel":"Cancel",
   "weekLabel":"W",
   "customRangeLabel":"Custom Range",
   "daysOfWeek":["Mo","Tu","We","Th","Fr","Sa","Su"],
   "monthNames":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
   "firstDay":1
}

Then I click on the element, which calls render(), which in turns calls setOptionsFromProps(), and it stomps all over the locale and turns it into {"firstDay":1}, which in turn causes errors in the underlying plugin because it expects to find keys on the locale object which no longer exist. If I don't try and configure the locale, everything works.

I'm not sure what the answer is here, but this is really not working. Is there another way to set the first day of the week?

Uncaught Invariant Violation: addComponentAsRefTo(...):

Hi skratchdot, great repo!
I have a problem though - when I try your example:

var React = require('react');
var moment = require('moment');
var DateRangePicker = require('react-bootstrap-daterangepicker');
var Period = React.createClass({
    render: function () {
        return (
            <DateRangePicker startDate={moment('1/1/2014')} endDate={moment('3/1/2014')}>
                <div>Click Me To Open Picker!</div>
            </DateRangePicker>
        );
    }
});

module.exports = Period;

it returns:

"Uncaught Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner)."

Do you have any idea, why that is?
Thanks in advance :)

0.2.3 -> 0.2.4 drops support for React 0.12

Hi,

My project declares separate dependencies for both react and react-bootstrap-daterangepicker.

I had declared these dependencies using the ~ operator to indicate that minor updates should be taken automatically (and I think that using the ^ operator would have the same effect given that both these dependencies are at the 0.x.x stage).

The automated build failed when 0.2.4 was released. I think that the change to drop support for React 0.12 is actually a breaking change, and therefore 0.2.4 should have been released as 0.3.0.

I have now stated the dependency as exactly 0.2.3, and my automated build has returned to normal.

I'm now investigating the use of npm shrinkwrap and explicit versioning to avoid this sort of thing in future, but I'd like to understand whether this particular break was accidental or by design?

Further, is it possible to release a new 0.2.5 and retain compatibility with React 0.12, or does the current codebase require 0.13?

Thanks in advance,
Stu.

Wrong date returned

Looks like something is wrong with returning selected dates. I have a initial date selected and stored in components state just like in the example. I have also onEvent callback attached which updates the state. When event hide is triggered it returns correct selected dates but just after that the apply event is triggered and that one still have picker object containing initial dates. So on hide event the state is updated to new value and just after that on apply event it gets reseted to previous value.

Cannot be used globally despite code that implies otherwise

I'm trying to use the DateRangePicker component by loading the JavaScript via my index.html. It should be possible thanks to this in daterangepicker.js:

// Finally, as a browser global.
} else {
  root.daterangepicker = factory(root, {}, root.moment || moment, (root.jQuery || root.Zepto || root.ender || root.$));
}

After it is executed, window.daterangepicker exists, but is undefined.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.