You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While upgrading my app to Polymer 2.0, I encountered a pretty nasty side effect of #130 (bindValue having a default value = ''), where persistent data is being wiped in situation like :
data.WILL_BE_DELETED is saved/synched between persistent layer (firebase) and paper-input.
Actual outcome
Persisted data is being wiped out because iron-input instantiate a default '' value, which is being notified to the persistent layer.
Fix
Prevent iron-input to notify upstream when the element is being attached (_initSlottedInput) and bindValue = "" (default value).
Tests are passing.
If this seems acceptable, I will propose a PR.
_initSlottedInput: function(){this._isInitiatingSlottedInput=true;this._inputElement=this.getEffectiveChildren()[0];if(this.inputElement&&this.inputElement.value){this.bindValue=this.inputElement.value;}this._isInitiatingSlottedInput=false;this.fire('iron-input-ready');},/** * @suppress {checkTypes} */_bindValueChanged: function(bindValue,inputElement){// The observer could have run before attached() when we have actually// initialized this property.if(!inputElement){return;}if(bindValue===undefined){inputElement.value=null;}elseif(bindValue!==inputElement.value){this.inputElement.value=bindValue;}if(this.autoValidate){this.validate();}// Note(cg): prevent notifying the change when initiating slotted input and bindValue is default. if(this._isInitiatingSlottedInput&&bindValue===''){return;}// manually notify because we don't want to notify until after setting valuethis.fire('bind-value-changed',{value: bindValue});},
Steps to reproduce
Example bellow will produce:
<html><head><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><metaname="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes"><title>iron-input demo</title><scriptsrc="../../webcomponentsjs/webcomponents-lite.js"></script><linkrel="import" href="../../iron-demo-helpers/demo-snippet.html"><linkrel="import" href="../../iron-demo-helpers/demo-pages-shared-styles.html"><linkrel="import" href="../../paper-input/paper-input.html"><!-- Order of imports matters. The validator needs to be imported before the iron-input needs it. --><linkrel="import" href="../iron-input.html"><custom-style><styleis="custom-style" include="demo-pages-shared-styles"></style></custom-style></head><dom-moduleid="app-test"><template><style>
:host {
display: block;
}
</style><ul><templateis="dom-repeat" items="[[logs]]"><li>name: [[item]]</li></template></ul><div>name: [[data.name]]</div></template><script>Polymer({is: 'app-test',properties: {data: {type: Object,notify: true,value: {}},logs: {type: Array,value: []}},observers: ['_observeData(data, data.*)'],_observeData(){this.push('logs',JSON.stringify(this.data));if(this.data&&this.data.name===''){this.push('logs','EMPTY !!!');}}});</script></dom-module></script><body><divclass="vertical-section-container centered"><h4>Basic inputs</h4><demo-snippetclass=""><template><dom-bindid="app"><template><app-testdata="{{data}}"></app-test><paper-inputplaceholder="name" label="my name" value="{{data.name}}"></paper-input></template></dom-bind></template></demo-snippet><script>window.addEventListener('WebComponentsReady',function(){constapp=document.querySelector('#app');app.data={name:'cg'}});</script></div></body></html>
Browsers Affected
Chrome
Firefox
The text was updated successfully, but these errors were encountered:
Description
While upgrading my app to Polymer 2.0, I encountered a pretty nasty side effect of #130 (bindValue having a default value = ''), where persistent data is being wiped in situation like :
Expected outcome
data.WILL_BE_DELETED
is saved/synched between persistent layer (firebase) and paper-input.Actual outcome
Persisted data is being wiped out because
iron-input
instantiate a default''
value, which is being notified to the persistent layer.Fix
Prevent
iron-input
to notify upstream when the element is being attached (_initSlottedInput) andbindValue
=""
(default value).Tests are passing.
If this seems acceptable, I will propose a PR.
Steps to reproduce
Example bellow will produce:
Browsers Affected
The text was updated successfully, but these errors were encountered: