question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cleave value doesn't update

See original GitHub issue

I have the following:

<Cleave 
    options={{date: true, datePattern: ['m', 'd', 'Y']}}  
    type="text" 
   value={this.state.initial_details.date}  
    onChange={ (data) => { 
          var data = this.state.data; 
          data.date = data.target.value; 
          this.setState({ data: data }) 
}} required />

While this does update my data.date as I type things into Cleave, if I change my state in an outside function, the input text stays the same in my Cleave text box which makes the end user think that there is data in the state variable when really there isn’t.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
nmiddendorffcommented, Feb 5, 2019

Hi @nosir, I looked at your solution for reseting a cleave input using setRawValue. Capturing the cleave instance on initialization seems unnecessary to me when I would expect the value prop on <Cleave /> to be capable of setting the new value.

However, I am unable to let the state manager (Redux in my case) to set the value to an empty string because of the following line: https://github.com/nosir/cleave.js/blob/27ebf3b56a03f3539cc33ac057f74b9298aebf0b/src/Cleave.react.js#L34

I am attempting to reset the value back to “” but because of the newValue !== owner.properties.initValue check the value does not get set because it is the initial value.

The following Sandbox will demonstrate that you are unable to reset the value after entering a value because this line prevents it from being set back to initValue. https://codesandbox.io/s/qqpln35mz9

I am wondering what the purpose of the newValue !== owner.properties.initValue check is. If this wasn’t there, consumers would no longer need to manually call setRawValue

4reactions
mgilbertiescommented, Apr 17, 2019

Any update on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

child component prop doesn't update after change on parent ...
I have component let's say "middle" with prop "element" from let's day "top" component - it's object and I use references to populate...
Read more >
Custom Directive not working well with last character (cleave ...
I tried to put $emit('update:value', event.target.value) into a nextTick but it doesn't work. Any help ?
Read more >
Cleave.js: format input Text Content When You Are Typing
Cleave.js has a simple purpose: to help you format input text content ... How to get ref of cleave instance and call methods...
Read more >
Cleave - MTG Keywords Explained - Card Kingdom Blog
The card's total mana value and color are determined by the normal mana cost. For Commander purposes, color identity can be affected by...
Read more >
Is it possible to make the answer entry boxes auto-expand ...
I have a constant sum question, and the cleave function works great on the first box, but then doesn't work on the rest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found