Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngValue): set value property instead of attr #14031

Closed
wants to merge 1 commit into from

Conversation

m-amr
Copy link
Contributor

@m-amr m-amr commented Feb 13, 2016

in case of input element set value using property instead of attribute
fixed #13984

* so we set both the value attribute and property here to avoid this problem.
*/
attr.$set('value', value);
elm[0].value = value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extract these two lines (along with the comment above) into a helper function to avoid duplication.

@gkalpak
Copy link
Member

gkalpak commented Apr 11, 2016

The docs also need to be updated to reflect the changes.

I would still add a breaking change note, since we are breaking a (documented-ish) assumption.
I can't think of any usecase, where this change would indeed break an app, but it is a breaking change.

@m-amr m-amr force-pushed the fix_ng-value_locally branch 2 times, most recently from 0dc6c46 to 7e84dd1 Compare April 11, 2016 23:21
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 11, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

Breaking Change:

NgValue is no longer updating the value attribute only when the model change,
because input element reads the value from value attribute only in case of value property has no value
but when value property changed the input element will stop reading the value from value attribute and
read it form the value propery.
so the input value in the gui will not equal the value of the model, becuase the model update the value attribute only.

Now ngValue updates both of value attribute and value property when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@m-amr m-amr force-pushed the fix_ng-value_locally branch from 7e84dd1 to 5080d7c Compare April 11, 2016 23:22
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 11, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

Breaking Change:

NgValue is no longer updating the value attribute only when the model change,
because input element reads the value from value attribute only in case of value property has no value
but when value property changed the input element will stop reading the value from value attribute and
read it form the value propery.
so the input value in the gui will not equal the value of the model, becuase the model update the value attribute only.

Now ngValue updates both of value attribute and value property when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@m-amr m-amr force-pushed the fix_ng-value_locally branch from 5080d7c to 8917b22 Compare April 11, 2016 23:28
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 11, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@m-amr
Copy link
Contributor Author

m-amr commented Apr 11, 2016

@gkalpak

  1. I have extracted a method to update the value to prevent code duplication .
  2. I have updating the commit message with the breaking change.
  3. I can't found anything to be update in the documentation.
    because the default behaviour of the ng-value is to update the input when the model change and this is a bug. please tell me if documentation is need to be updated ?

Thanks for your feedback.

@m-amr m-amr force-pushed the fix_ng-value_locally branch from 8917b22 to 6c1ae85 Compare April 11, 2016 23:38
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 11, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@gkalpak
Copy link
Member

gkalpak commented Apr 13, 2016

WRT to the docs, e.g. somewhere it says that the resulting "value will be bound to the value attribute of the input element", which is not accurate anymore.

The docs need a more thorough make-over anyway, because they mention option and input[radio] elements, but with this change ngValue can be used for more purposes, so I can take care of the docs update while mergin or later.

It LGTM.
@Narretz, since you were working on some ngValue stuff, do you have any objection/concerns about this ?

@Narretz
Copy link
Contributor

Narretz commented Apr 13, 2016

I would like to see the setter code to be more precise in terms of which elements need attribute set and which need property set. So basically the setter fn should be set up based on the element type. I assume the value property should be set for textarea and input[text], while option and input[radio|checkbox] are good with attribute only.
And the docs must be updated. Atm, the docs are pretty explicit that the directive is only for radio/checkbox and option elements.
So the change is actually a feature and not a fix.

@m-amr
Copy link
Contributor Author

m-amr commented Apr 13, 2016

@Narretz I think that the setter is setting the property in case of boolean values only, i tried ti fix it in this pull request #14023

@Narretz
Copy link
Contributor

Narretz commented Apr 13, 2016

@m-amr I'm not sure I follow. Input elements / controls cannot have boolean values. Their values are always string values. Angular models are a different situation, but they generally follow this rule, with exceptions.

m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 18, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@m-amr m-amr force-pushed the fix_ng-value_locally branch from fa2a50b to aad98d8 Compare April 18, 2016 19:33
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 18, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@m-amr
Copy link
Contributor Author

m-amr commented Apr 18, 2016

@Narretz @gkalpak
Could you please give it another look, i have done the following

  1. use prop function to set the value instead of element.value
  2. remove redundant code from tests
  3. i had updated the docs

Thanks.

@m-amr m-amr force-pushed the fix_ng-value_locally branch from aad98d8 to c9d2a9d Compare April 18, 2016 19:36
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 18, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@m-amr m-amr force-pushed the fix_ng-value_locally branch from c9d2a9d to 9bdc680 Compare April 18, 2016 19:37
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 18, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@@ -1701,6 +1701,11 @@ var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/;
* so that when the element is selected, the {@link ngModel `ngModel`} of that element is set to
* the bound value.
*
* It can be used to achieve one-way binding of a given expression to the value of
* {@link input[text] `input[text]`} or {@link textarea `textarea`}. so that when the expression change
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only input[text]. Won't it work with any input type ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to change it to be input type

@gkalpak
Copy link
Member

gkalpak commented Apr 22, 2016

I would like to see the setter code to be more precise in terms of which elements need attribute set and which need property set. So basically the setter fn should be set up based on the element type. I assume the value property should be set for textarea and input[text], while option and input[radio|checkbox] are good with attribute only.

I'd rather set both and not worry about browser quirks (unless this "strategy" would lead to problems).
@Narretz, do you know of any usecase, where setting both would be a problem ?

@m-amr m-amr force-pushed the fix_ng-value_locally branch from 9bdc680 to 092ef36 Compare April 22, 2016 13:19
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 22, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@m-amr m-amr force-pushed the fix_ng-value_locally branch from 092ef36 to a164453 Compare April 22, 2016 13:20
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 22, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@@ -1701,6 +1701,10 @@ var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/;
* so that when the element is selected, the {@link ngModel `ngModel`} of that element is set to
* the bound value.
*
* It can be used to achieve one-way binding of a given expression to the value of
* {@link input `input`}. so that when the expression change the element is set to the bound value.
Copy link
Member

@gkalpak gkalpak Apr 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input --> an element
. --> ,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@m-amr m-amr force-pushed the fix_ng-value_locally branch from a164453 to dbcf123 Compare April 25, 2016 22:26
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 25, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@m-amr m-amr force-pushed the fix_ng-value_locally branch from dbcf123 to 24b7df6 Compare April 25, 2016 22:28
m-amr added a commit to m-amr/angular.js that referenced this pull request Apr 25, 2016
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@m-amr m-amr force-pushed the fix_ng-value_locally branch from 24b7df6 to 6f8aa1d Compare April 25, 2016 22:34
…ribute only

input element reads the value from value property and override the value attribute so we need to set both

Closes angular#14031
Closes angular#13984

BREAKING CHANGE:

NgValue is no longer updating the "value attribute" only when the model change,
because input element reads the value from "value attribute" only in case of "value property" has no value
but when "value property" changed the input element will stop reading the value from "value attribute" and
read it form the "value property".
so the input value in the gui will not equal the value of the model, becuase the model update the "value attribute" only.

Now ngValue updates both of "value attribute" and "value property" when the model change
This shouldn't affect any application becuase this is a bug and input value in the gui should be updated when the model change
@Narretz
Copy link
Contributor

Narretz commented Apr 26, 2016

@gkalpak I don't know of any way this could cause problems. I was just conservative, I guess.
The BC notice needs some love, because it's a bit hard to understand, otherwise LGTM.

@Narretz Narretz self-assigned this Jul 28, 2016
Narretz pushed a commit to Narretz/angular.js that referenced this pull request Aug 8, 2016
…ue attribute

Input elements use the value attribute as their default value if the value property is not set.
Once the value property has been set (by adding input), it will not react to changes to
the value attribute anymore. Setting both attribute and property fixes this behavior, and
makes it possible to use ngValue as a one-way bind.

Closes angular#14031
Closes angular#13984

POSSIBLE BREAKING CHANGE:

`ngValue` now also sets the value *property* of its element. Previously, it would only set the
value *attribute*. This allows `ngValue` to be used as a one-way binding mechanism on `input[text]`
and `textarea` elements without `ngModel`. Previously, these input types would not update correctly
when only the value attribute was changed.
This change should not affect any applications, as `ngValue` is mainly used on `input[radio]` and
`option` elements, both of which are unaffected by this change.
Narretz pushed a commit to Narretz/angular.js that referenced this pull request Aug 8, 2016
…ue attribute

Input elements use the value attribute as their default value if the value property is not set.
Once the value property has been set (by adding input), it will not react to changes to
the value attribute anymore. Setting both attribute and property fixes this behavior, and
makes it possible to use ngValue as a one-way bind.

Closes angular#14031
Closes angular#13984

POSSIBLE BREAKING CHANGE:

`ngValue` now also sets the value *property* of its element. Previously, it would only set the
value *attribute*. This allows `ngValue` to be used as a one-way binding mechanism on `input[text]`
and `textarea` elements without `ngModel`. Previously, these input types would not update correctly
when only the value attribute was changed.
This change should not affect any applications, as `ngValue` is mainly used on `input[radio]` and
`option` elements, both of which are unaffected by this change.
Narretz pushed a commit to Narretz/angular.js that referenced this pull request Aug 8, 2016
…ue attribute

Input elements use the value attribute as their default value if the value property is not set.
Once the value property has been set (by adding input), it will not react to changes to
the value attribute anymore. Setting both attribute and property fixes this behavior, and
makes it possible to use ngValue as a one-way bind.

Closes angular#14031
Closes angular#13984

POSSIBLE BREAKING CHANGE:

`ngValue` now also sets the value *property* of its element. Previously, it would only set the
value *attribute*. This allows `ngValue` to be used as a one-way binding mechanism on `input[text]`
and `textarea` elements without `ngModel`. Previously, these input types would not update correctly
when only the value attribute was changed.
This change should not affect any applications, as `ngValue` is mainly used on `input[radio]` and
`option` elements, both of which are unaffected by this change.
@Narretz Narretz closed this in e6afca0 Aug 9, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngValue one way binding?
4 participants