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

[2.0-preview] dom-bind not working in preview #54

Open
ghost opened this issue Mar 14, 2017 · 6 comments
Open

[2.0-preview] dom-bind not working in preview #54

ghost opened this issue Mar 14, 2017 · 6 comments

Comments

@ghost
Copy link

ghost commented Mar 14, 2017

Using the Polymer v2.0.0-rc.2 with the iron-demo-helpers 2.0-preview, data binding within the template is not working.

This following used to work in Polymer v1.x:

<demo-snippet>
  <template is="dom-bind">
     <nebula-location data="{{location}}"></nebula-location>
     <p>Pathname: <b>[[location.pathname]]</b></p>
  </template>
</demo-snippet>

To get this to work now I have to add an additional dom-bind wrapper inside the demo-snippet:

<demo-snippet>
  <template>
    <dom-bind>
      <template>
        <nebula-location data="{{location}}"></nebula-location>
        <p>Pathname: <b>[[location.pathname]]</b></p>
      </template>
    </dom-bind>
  </template>
</demo-snippet>

But now the dom-bind wrapping is also shown in the clipboard preview area.

@masonlouchart
Copy link

Same issue with Polymer 2.0.1 and iron-demo-helpers 2.0.0.

masonlouchart added a commit to convoo/reverse-element that referenced this issue Jun 23, 2017
Since the element is hybrid, when it uses Polymer 2 the demo page is
broken. It seems this is a known issue related to the [iron-demo-helpers](PolymerElements/iron-demo-helpers#54).
@cecilia-sanare
Copy link
Contributor

cecilia-sanare commented Jul 21, 2017

Changing the following function fixes the issue, but I suspect it
may have some unforeseen consequences since I'm having to
use querySelector directly.

<demo-snippet>
  <dom-bind>
    <template>
      <input type="checkbox" checked="{{opened::change}}">
      <input type="checkbox" checked="{{opened::change}}">
    </template>
  </dom-bind>
</demo-snippet>

demo-snippet.html

// ...
_updateMarkdown: function() {
  var template = Polymer.dom(this).queryDistributedElements('template')[0];

  // Attempt to find any child node that represents a template
  // This fixes utilizing dom-bind w/ a template
  if (!template) {
    template = Polymer.dom(this).querySelector('dom-bind > template, dom-repeat > template, dom-if > template');
  }

  // If there's no template, render empty code.
  if (!template) {
    this._markdown = '';
    return;
  }
  var is = template.is || template.parentElement.tagName.toLowerCase();
  var snippet = this.$.marked.unindent(template.innerHTML);
  // Boolean properties are displayed as checked="", so remove the ="" bit.
  snippet = snippet.replace(/=""/g, '');
  this._markdown = '```\n' + snippet + '\n' + '```';
  // Stamp the template.
  if (['dom-if', 'dom-bind', 'dom-repeat'].indexOf(is) === -1) {
    // Don't need to listen for more changes (since stamping the template
    // will trigger an observeNodes)
    Polymer.dom(this.$.content).unobserveNodes(this._observer);
    this._observer = null;
    Polymer.dom(this).appendChild(document.importNode(template.content, true));
  }
},
// ...

@heruan
Copy link

heruan commented Nov 3, 2017

I'm experiencing this in demo-helpers v2.0.0. For example:

<demo-snippet>
  <template is="dom-bind">
     <paper-input value="{{value}}"></paper-input>
     <p>Value: <span>[[paper-input]]</span></p>
  </template>
</demo-snippet>

renders a blank snippet:

screen shot 2017-11-03 at 16 11 47

But if I remove is="dom-bind" the input appears, without binding of course.

Is it a bug or is it by design?

@masonlouchart
Copy link

masonlouchart commented Nov 3, 2017

Hi @heruan, adding dom-bind tags worked for me:

<demo-snippet>
  <template>
+  <dom-bind>
    <template is="dom-bind">
      <paper-input value="{{value}}"></paper-input>
      <p>Value: <span>[[paper-input]]</span></p>
    </template>
+  </dom-bind>
  </template>
</demo-snippet>

EDIT: after comment of @Stefdv

@SieBRUM
Copy link

SieBRUM commented Nov 13, 2017

Why is this still not fixed? After applying those fixed, the PREVIEW is rendered, but the code snippet is not..

@Stefdv
Copy link

Stefdv commented Jan 19, 2018

I think @masonlouchart means

<demo-snippet>
  <template>
    <dom-bind>
      <template is="dom-bind">
          <paper-input value="{{value}}"></paper-input>
          <p>Value: <span>[[value]]</span></p>
      </template>
    </dom-bind>
   </template>
</demo-snippet>

That is an awfull lot off tags but at least it works ;p

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

No branches or pull requests

5 participants