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

Input value is not initialised. #213

Closed
treshugart opened this issue Jul 19, 2013 · 4 comments
Closed

Input value is not initialised. #213

treshugart opened this issue Jul 19, 2013 · 4 comments

Comments

@treshugart
Copy link

Given the following element and accompanying model, the input is not initialised with the default title of "asdf".

<polymer-element name="todo-list">
  <template>
    <form>
      <input id="title" type="text" value="{{ title }}" placeholder="New Todo Title">
      <button type="button" on-click="add">Add</button>
    </form>
    <ul>
      <template repeat="{{ todos }}">
        <li>{{ title }}</li>
      </template>
    </ul>
  </template>
  <script>
    Polymer('todo-list', {
      title: 'asdf',
      todos: [],
      add: function() {
        this.todos.push({ title: this.title });
        this.$.title.value = '';
      }
    });
  </script>
</polymer-element>
@sjmiles
Copy link
Contributor

sjmiles commented Jul 19, 2013

Unfortunately, title is a native property on HTMLElement, so you cannot currently override it successfully (aka put a title property in your prototype).

Change the name title to something else (e.g. caption) and that should fix the problem.

@treshugart
Copy link
Author

Sweet, thanks. That's was unclear because I wasn't using title as part of an HTMLElement but only in the model (and to retrieve it by its id). This seems then that Polymer is storing model data as attributes on an HTMLElement?

@sjmiles
Copy link
Contributor

sjmiles commented Jul 19, 2013

Yes, the view-model for an element is itself. That doesn't mean it has to be the same as your business-model (so to speak), but you can hang business-model objects off of the element to make them accessible in the view.

@treshugart
Copy link
Author

That's so rad! I just wrote a test for this and it works. I had thought to use element.model.title since in the documentation it sets the model property to initialise the model in one of the examples but didn't see anywhere how to access the properties themselves, hence my confusion.

Thanks again!

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

2 participants