3

I am trying to find a way to reset a form inside a dialog back to some default data after the dialog is closed/abandoned.

Say collaborators is a list from the server, each with an associated privilege level. My form provides a way to edit their privilege. If they abandon the dialog (without clicking submit), it should revert to their saved privilege, no matter what they selected in the dropdown.

When they abandon the dialog, I try doing this.$.users.render() to force the dom-repeat to re-compute _computeDropdown (which returns a paper-item index) and get rid of the user selection, even though items hasn't changed.

But render doesn't call the computed binding. Am I overlooking another way to reset the selection to default data here?

<template id="users" is="dom-repeat" items="[[ collaborators ]]">

    <div class="field">
        <paper-input disabled name="collaborator" label="[[ item.name ]]"></paper-input>
        <paper-icon-button icon="close" on-tap="remove"></paper-icon-button>
        <paper-dropdown-menu name="privilege">
            <paper-listbox class="dropdown-content" selected="[[ _computeDropdown(item.privilege) ]]">
                <paper-item>Owner</paper-item>
                <paper-item>Collaborator</paper-item>
            </paper-listbox>
        </paper-dropdown-menu>
    </div>

</template>
yglodt
  • 13,807
  • 14
  • 91
  • 127
kriscooke
  • 31
  • 3
  • For now, I am using this method to hack around it. Add a dependency to the computed binding, `_computeDropdown(item.ownership, _updateHack)` and then change `_updateHack` when I want it to re-evaluate... http://stackoverflow.com/questions/27206003/manually-recalculate-computed-properties – kriscooke Dec 09 '15 at 22:27

1 Answers1

1

The dom-repeat has an observe attribute.

<template id="users" is="dom-repeat" items="[[ collaborators ]]"
    observe="_updateHack">

should do the same.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Oh interesting, yes. Still requires an _updateHack prop to change though. I suppose this is just Polymer trying to be really sparing on unnecessary updates; I must admit this is the only case I've really come across this need where it's not enough to observe an existing prop. – kriscooke Dec 15 '15 at 00:15