Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paper-input: Fix md-input-has-value when value attr is not observable #412

Conversation

dustinfarris
Copy link
Contributor

@dustinfarris dustinfarris commented Jul 3, 2016

Given the API for paper-input, we cannot assume that the user is going to update the original value object in their provided onchange closure. We also cannot assume that the provided value is observable.

This adds a new property to track the actual value of the input for things like binding the md-input-has-value class.

Fixes #411

@dustinfarris dustinfarris force-pushed the input-internal-value branch from 4b6464b to c8094bd Compare July 3, 2016 06:19
@miguelcobain
Copy link
Collaborator

Given the API for paper-input, we cannot assume that the user is going to update the original value object in their provided onchange closure.

Where do we assume that?

We also cannot assume that the provided value is observable.

What do you mean? We're just using a computed property which depends on value. I don't see a case where that isn't "observable".

@dustinfarris
Copy link
Contributor Author

@miguelcobain look at the last test I wrote for this PR. That test fails without the proposed change.

@dustinfarris
Copy link
Contributor Author

@miguelcobain in that test the provided "value" is a static empty string (not observable). Also onChange does nothing. So while the value of the input changes, nothing else happens. But for purposes of applying the right classes such as md-input-has-value we need to track the actual change of the input without caring necessarily if the user could or did update the value in the onchange action.

@miguelcobain
Copy link
Collaborator

@dustinfarris paper-input should reflect whatever value it gets from outside. That's the DDAU philosophy.
So, I think a hasValue property should be true only if the outside world did update that value.

@dustinfarris
Copy link
Contributor Author

dustinfarris commented Jul 3, 2016

@miguelcobain DDAU is still honored by making this a oneway, but we also have to honor MD style rules with the input element itself when its internal value deviates as could easily happen. Otherwise we have bugs like #411

@miguelcobain
Copy link
Collaborator

miguelcobain commented Jul 3, 2016

Let's imagine the following scenario:

  • user types "aaa"
  • with your PR, paper-input will overwrite _internalValue with "aaa", making it no longer a oneWay binding (Correct me if I'm wrong, please.)
  • onChange is triggered 3 times
  • for some reason, the user wants this specific input to be emptied when length is 3. The user does that in the action and updates value.
  • since _internalValue is no longer bound to value you end up with different value and _internalValue

In this case I don't think this PR honors DDAU entirely because: the component should always reflect the state it is given (data down).

@dustinfarris
Copy link
Contributor Author

Ok, I am unsure how computed oneway will react to an update like that after it deviated. I'll write a test for this when I'm back at my desk and adjust the implementation if necessary.

@miguelcobain
Copy link
Collaborator

Strange things happen when you don't update the input's value in normal ember/hbs.

Example: https://ember-twiddle.com/a0f4c6ce8ab25734634aadc74e76509d

In that twiddle the user wanted to always have 123 regardless of what the user types.
It only works on the first time. It is complicated. Previous discussions about this on ember's slack ended up with no solution.

@dustinfarris
Copy link
Contributor Author

Ok agreed that this may not be the right approach. The end goal here is to make sure that we apply the md class if the input element has a value. I will rethink implementation to achieve that.

@miguelcobain
Copy link
Collaborator

Thank you for your time.

@dustinfarris
Copy link
Contributor Author

@miguelcobain I've added an observer to ensure that future changes to value are reflected as you would expect with DDAU philosophy. Also renamed hasValue to inputHasValue to more accurately describe what is being referred to (_internalValue is now inputValue). There is an additional test to show this working.

I believe this is good to merge now.

@dustinfarris dustinfarris force-pushed the input-internal-value branch from ffa5f20 to 599d1f6 Compare July 4, 2016 12:32
This one-way property allows us to keep a current copy of the input's
value for internal use when the `value` attr is not updated by the
user in the usual way.

Changed hasValue to inputHasValue referencing inputValue instead of value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants