-
-
Notifications
You must be signed in to change notification settings - Fork 145
Conversation
…ver this solution works only if the line `value={value}` in the `render` function is commented.
src/components/Input.react.js
Outdated
@@ -25,25 +25,29 @@ export default class Input extends Component { | |||
setProps, | |||
type | |||
} = this.props; | |||
const {value} = this.state; | |||
//const {value} = this.state; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you comment this out, it will mean that a Dash user cannot provide the value
prop to the dcc.Input
component (or rather, it will not do anything). You can see in the constructor
of the class that this.state.value
is set to props.value
, and below in <input />
, it gets set to the value attribute: <input value={value} />
.
src/components/Input.react.js
Outdated
}} | ||
value={value} | ||
} | ||
//value={value} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason that this doesn't work without removing the value={value}
, is probably because onBlur
only fires the update, well, on blur, as opposed to onChange
which fires every change. Setting value
here will overwrite anything you put in the input (try having just <input value={value} />
in there, and you'll see what I mean - it is as if it's 'locked' to whatever is put in as the value
prop) so onBlur
will fire it's update on blur, but because the input is 'locked', it fires the update with the same value. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it make sense, maybe it could work with another variable, i.e. typed
for example. I will try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I Added a prop typed
to the state (Is it the proper way to say this?), this gets updated by onChange , the
valueprop takes the value of the
typeprop when
onBlur``gets fired, so now it works (at least on windows 10)
…s the prop `value` by `typed`, that way we don't need to comment out the line `value={value}`
When I try to get the details of the Percy tests I get the following error :
I guess I should update the changelog by pulling the latest version of master before merging? |
I'll need to add you to percy first
Yeah, or rebase on master and then update the changelog |
Couldn't we use |
…epper which gets rendered in firefox for an `<input type=number>`
For this bug, I'd rather write the logic ourselves rather than introduce more dependencies |
The fix I found works except that it requires that the
instead of
I did that because I introduced another prop in |
Assigning For the logic of this component do we want that the value gets changed at every keystroke? or only when the user is done writing? |
Considering the case for decimal numbers, trying to type out
Both solutions would be valid. (1) is strictly correct but (2) seems like it would satisfy the users who reported the bug in #169 and provide a new feature in general. |
…r dash callback on 'value' changes at at every keystroke, still some bug when the `type` prop is set to `number`) or blur (trigger dash callback on 'value' changes only when the user click somewhere else or press tab). When the `type` prop is set to `number`, then pressing on the lateral steppers button will immediately trigger a callback on 'value' change.
# Conflicts: # src/components/Input.react.js
@valentijnnieman I am not sure how I should make --edit : nevermind I found that by looking at the slider code :) |
… the user cannot type anything else than [0-9], the comma, the dot and the minus sign. The minus sign must be in first place and the comma and the dot are limited to one instance only and are mutually exclusive (if there is a dot, one cannot type a comma)
One thing that I am unable to control now is that the used is allowed to feed a string with content not matching a number format, i.e.
Another thing (maybe linked) is that the user is allowed to type in a wrong number format (i.e. it displays it although the value of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left you a couple of comments! Looks like it's getting there though! :)
src/components/Input.react.js
Outdated
<input | ||
onBlur={() => { | ||
const newValue = formatValue(this.state.value, type); | ||
if (updatemode === 'blur') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, if updatemode
is an array (i.e. ['blur', 'enter']
) this will not trigger. The best way to do this would probably be to first see if updatemode
is an array (you could use Ramda's is
function for that, something like R.is(Array, updatemode)
) and then check if that array contains blur
(Ramda has a contains function that can do that easily)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe even if (updatemode === 'blur' || R.contains('blur', updatemode)) {}
will work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I implemented with updatemode
being blur
(update when pressing tab or clicking away) or keypress
(update at everykeystrokes), I wasn't sure the if we really need to have ['blur', 'enter']
but I kept it in the Input.Props
src/components/Input.react.js
Outdated
onChange={e => { | ||
const newValue = formatValue(e.target.value, type); | ||
this.setState({value: newValue}); | ||
if (updatemode === 'keypress') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here - this if
only works if updatemode
is a string, not when it's an array.
src/components/Input.react.js
Outdated
) { | ||
e.preventDefault(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain a bit about what this code is supposed to do? Is it really necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rejects the onKeyPress
event and the onChange
event is therefore not triggered. This is used to make sure the user can only press on 0-9, dot and comma and that the user cannot input Something like 0.122.,233,44.4
, it prevents the use of another dot or comma when either one of them is already present
Nice! Couple of tiny things though.
I'm not sure if the way to go here is to prevent all these types of inputs. I think having the normal behaviour of an @chriddyp Could you weigh in on this? |
However I also have the problem of being able to input many dots. I can fix it, but it could also be decided that it is better to leave the user able to input more freely as you suggested :) |
Going to close this because the issues have been fixed in #356 |
fixes plotly/dash-core_components#169
Fix the decimal problem by using
onBlur
instead ofonChange
. However this solution works only if the linevalue={value}
in therender
function is commented.