-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(ngValue): set value property instead of attr #14031
Conversation
a98660c
to
c179cce
Compare
* so we set both the value attribute and property here to avoid this problem. | ||
*/ | ||
attr.$set('value', value); | ||
elm[0].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.
Could you extract these two lines (along with the comment above) into a helper function to avoid duplication.
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. |
0dc6c46
to
7e84dd1
Compare
…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
7e84dd1
to
5080d7c
Compare
…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
5080d7c
to
8917b22
Compare
…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
Thanks for your feedback. |
8917b22
to
6c1ae85
Compare
…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
WRT to the docs, e.g. somewhere it says that the resulting "value will be bound to the The docs need a more thorough make-over anyway, because they mention It LGTM. |
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. |
@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. |
…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
fa2a50b
to
aad98d8
Compare
…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
aad98d8
to
c9d2a9d
Compare
…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
c9d2a9d
to
9bdc680
Compare
…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 |
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.
Why only input[text]
. Won't it work with any input type ?
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 have to change it to be input type
I'd rather set both and not worry about browser quirks (unless this "strategy" would lead to problems). |
9bdc680
to
092ef36
Compare
…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
092ef36
to
a164453
Compare
…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. |
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.
input --> an element
.
--> ,
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.
Done.
a164453
to
dbcf123
Compare
…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
dbcf123
to
24b7df6
Compare
…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
24b7df6
to
6f8aa1d
Compare
…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 I don't know of any way this could cause problems. I was just conservative, I guess. |
…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.
…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.
…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.
in case of input element set value using property instead of attribute
fixed #13984