How to bind a date to an element attribute in template

(Maybe this is an Ember.data issue.)

I’m trying this:

<dt>Downtime Begin</dt><dd {{bind-attr title=downtime_date_begin}}>{{format-date downtime_date_begin}}</dd>

And I’m getting this:

Uncaught Error: Assertion Failed: Attributes must be numbers, strings or booleans, not Tue Dec 31 2013 18:00:00 GMT-0600 (Central Standard Time) 

I think I understand the explanation, that the value I’m trying to bind to the attribute is ineligible for such a use. However, I don’t know what the alternative is. Maybe create a computed property in the controller and then bind that computed property to the element?

TIA!

Perhaps use a handlebars helper. Just like {{format-date date}}

https://github.com/broerse/ember-cli-blog/blob/master/app/templates/post.hbs

Thank you, @broerse !

I was trying to modify an attribute of an element (in this case the title attribute of the DD element). It doesn’t appear that your code does that, but maybe I’m missing something. Is there a way to apply arbitrary values (i.e., regardless of data type) to an element’s attribute without using a custom helper to create the element?

As HTML attributes need to be valid syntax, it seems like the bind-attr helper doesn’t attempt to sanitize the rendering of arbitrary data, but expects to receive only simple data types. You could use a computed property that renders the original date property as string, e.g. with moment.js

1 Like

I overlooked but yes @rainerfrey is right bind-attr attributes must be numbers, strings or booleans.

See also:

1 Like