y0c / react-datepicker

📅 React DatePicker Library (Flexible, Reusable)
https://y0c.github.io/react-datepicker
MIT License
168 stars 32 forks source link

Clear date inputs dosn't fire onChange props method! #58

Open kleviscipi opened 4 years ago

kleviscipi commented 4 years ago

Using RangeDatePicker in combination with props clear, the event fire doesn't call the method onChange . I am using this library and it is great but is very necessary for me to have that feature. A props *onClear should be great, which is called when handleInputClear (inside the RangeDatePicker) is fired

SarahAlAshwal commented 3 years ago

@kleviscipi did you find a solution for that ?

manish-sh14 commented 2 years ago

This is an open issue still we are facing. Did any update happen on this?

kleviscipi commented 2 years ago

@manish-sh14 @SarahAlAshwal

I'm using the prop inputComponent to generate an element (input) by my self with default date values and i'm not using the clear features.

Something like this:

            <DatePicker 
                onChange= {this.onChange}
                locale="it"
                portal={this.props.portal||false}
                icon={this.getIcon()}
                placeholder={this.props.placeholder||""}
                inputComponent={(props)=>{
                    let newProps = props

                    if(!this.getValue()){
                            newProps.value = ""
                    }

                    if( this.state.value && this.getValue() ){
                        newProps.value = this.state.value
                    }
                    return <input type="text" className="form-control" {...newProps} />
                }}
                initialDate={this.props.initialDate}
            />