Gusto / react-masked-field

A masked input component built in React
MIT License
19 stars 7 forks source link

How can masked input be cleared #12

Open BotOfTheBots opened 7 years ago

BotOfTheBots commented 7 years ago

As header states i do not find any way to clear masked input.

This works:

const React = require('react')
const MaskedField = require('react-masked-field');

class MaskedInput extends React.Component {

  componentWillReceiveProps(nextProps){
    if(!nextProps.value)
      this.refs.inputElement.setState({value: ""})
  }

  render() {
    return (
      <MaskedField
        ref="inputElement"
        id={"date-from"}
        mask="2999-19-39"
        translations={{'1': /[0-1]/, '2': /[1-2]/, '3': /[0-3]/, '9': /[0-9]/}}
        placeholder="date from"
        onComplete={this.props.selectDateFrom}
        onBlur={this.props.validateDate}
      />
    )
  }
}

module.exports = MaskedInput;

The way that it hides the value and it looks like it was cleared but when input is clicked again the old value shows up. Is it possible to clear masked input programmatically?

acomito commented 5 years ago

I'm seeing this too. I have a birthday input inside of a wizard form. The birthday input is used on multiple pages of the wizard and values are bleeding over from other pages.