input value behavior on update #1612

Closed
whatda opened this Issue Feb 18, 2016 · 18 comments

Projects

None yet

7 participants

@whatda
whatda commented Feb 18, 2016

https://plnkr.co/edit/NIhZsohAsCyhnykGeTvI?p=preview

When you click on the new (+) button, the input is emptied. If you fill in some random value and then click new (+) again, the value is not updated, although this is explicitly stated in modal.tag under the event handler for "newEntity".

Question: I would assume this behavior is aimed towards protecting user inputs from being accidentally overwritten by "old" data on update. Problem: I explicitly re-set the element to that "new" value, so my setting is actually newer than the user input and should imo be preferred.

I hope the problem here is clear. If not, don't hesitate to ask questions.

Any ideas how to handle this? Is it a bug or is it a feature?

Thanks.

@acousticseagull

You never set entity.title to the value of the input.

@jmk2142
jmk2142 commented Feb 18, 2016

This sounds somewhat similar to a problem I had. See earlier issue #1602 It might point you in the right direction.

@acousticseagull

Is this what your trying to do?

@GianlucaGuarini
Member

@acousticseagull thanks I think your clean example is what @whatda is trying to achieve.

@whatda
whatda commented Feb 19, 2016

Thanks for your replies.

@acousticseagull I don't want it to be the value of the input, I want the value of the input to be the entities value! The +-button is supposed to set the input to a new "clean" value, which can then be edited by the user. The problem now is that if you type a random value into the input and then click "+", the value is not re-set to the clean value.

@jmk2142 You had an error in your code, as far as I can see. I don't see an error in my code.

@GianlucaGuarini Nope, sorry. It's not. On +-button click the entity's title is replaced with a value and update is called. But if you type something random in and click + again, the input's value is not updated to the "clean" value, that's my problem.

@rsbondi
Contributor
rsbondi commented Feb 19, 2016

@jmk2142 has given the correct answer. You set this.entity.title = '' and never set it to anything else unless you hit edit. It only updates the dom when something changes. Setting '' to '' is not a change.

@whatda
whatda commented Feb 19, 2016

@rsbondi Okay, thanks. I think I'm getting it now. Is there some sort of "refresh()" function which will update all input values to equal the referenced expressions? I bascially would like to force the update then, no matter if something changed.

@GianlucaGuarini
Member

Is there some sort of "refresh()" function which will update all input values to equal the referenced expressions?

http://riotjs.com/api/#updating

@whatda
whatda commented Feb 19, 2016

Aye-aye, I'll check that out, thx.

@whatda whatda closed this Feb 19, 2016
@whatda
whatda commented Feb 22, 2016

@GianlucaGuarini I'm sorry, but I can't find any methods in the referenced docs that would solve this issue. I've tried the alternative update syntax, but as written its behavior is the same.

https://plnkr.co/edit/NIhZsohAsCyhnykGeTvI?p=preview

Steps to reproduce:

  1. Don't do anything, just notice that the inputs value it set to "initial value"
  2. Click the "+"-button. The input is set to an empty string as specified in modal -> newEdity handler.
  3. Enter a random value into the input -> Notice that the input now doesn't reflect the underlying object
  4. Click the "+"-button. The input now continues to contain your random value <-- That's the issue

Is that resolvable with the current riot approach? What alternatives does one have?

Basically I'd like a complete refresh of the tag's html.

@whatda whatda reopened this Feb 22, 2016
@GianlucaGuarini GianlucaGuarini added bug and removed answered question labels Feb 22, 2016
@GianlucaGuarini
Member

to me this seems to be a bug this is a workaround. Here there is the version where the bug appears

@whatda
whatda commented Feb 22, 2016

@GianlucaGuarini Thanks! After the post of @rsbondi I noticed that update is probably not the right choice for my special use case, because the value of the entity hasn't changed (I just reassigned the existing value) and as such riot behaves correctly not to update the input expression. If it would, it would always overwrite user inputs on each update, which is probably very wrong in most cases (imagine the user typing something and it's suddenly gone after an update).

In my opinion it would be nice to have a refresh method or a parameter for update, which will simply re-evaluate each expression, regardless of value changes. But I'm open to better arguments, of course.

@GianlucaGuarini
Member

I have already fixed the problem, I am preparing the tests to avoid this issue in the future. Thanks for reporting it

@GianlucaGuarini GianlucaGuarini added a commit that referenced this issue Feb 22, 2016
@GianlucaGuarini GianlucaGuarini closes #1612 8ea4bac
@GianlucaGuarini GianlucaGuarini added a commit that closed this issue Feb 27, 2016
@GianlucaGuarini GianlucaGuarini closes #1612 8ea4bac
@aMarCruz aMarCruz added a commit to aMarCruz/riot that referenced this issue Mar 1, 2016
@aMarCruz aMarCruz Regression of #1612
Update the dom only if the value of the expression was changed.
df6e026
@GianlucaGuarini
Member

this issue was fixed in riot 2.3.16 but being a breaking change it will be removed in the next riot patch release. It will be fixed in riot 3.0.0

@GianlucaGuarini GianlucaGuarini modified the milestone: 2.3.0, 3.0.0 Mar 1, 2016
@GianlucaGuarini GianlucaGuarini added a commit that referenced this issue Mar 1, 2016
@GianlucaGuarini GianlucaGuarini closes #1612 1a51aab
@joshgillies

@GianlucaGuarini was a breaking change really introduced in the last patch release 2.3.16?

I'm all for this patch getting in, but we need to maintain reliable releases with Riot. Luckily in our case we caught this regression in a staging environment. I doubt others will have been as fortunate.

Please if you're doing semver, try to do it in a predictable fashion. Can I suggest riot@2.3.16 be removed from npm to avoid this causing issues for others moving forward.

@SomeoneWeird

+1 this was an issue for us too

@GianlucaGuarini
Member

don't worry guys I will publish riot@2.3.17 soon adding a deprecation message for riot@2.3.16 ;)

@GianlucaGuarini
Member

this issue must be closed we will decide how input and select tags will behave on the updates here #1642

@cognitom cognitom referenced this issue Nov 26, 2016
Merged

Fix #2096 #2099

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment