cyclotron
cyclotron copied to clipboard
dataSource value passed to moment function does not render properly
I created an HTML widget and in the HTML section, I put the following code:
<p>Date: #{openingDate}</p>
<p>Date: ${moment(#{openingDate}).format('YYYY-MM-DD')}</p>
Expected Output:
Date: 2015-10-15T00:05:32.000Z Date: 2015-10-15
Actual Output:
Date: 2015-10-15T00:05:32.000Z Date: ${moment(#{openingDate}).format('YYYY-MM-DD')}
If there's an error in the inline JavaScript (${...}
), Cyclotron just dumps the original value out and logs an error into the console. That's what's happening here. In this case, I'm pretty sure the issue is that ${openingDate}
is a string, but it's not quoted. Cyclotron doesn't automatically handle this, it just inlines the values as-is and tries to execute.
This version should fix the issue:
<p>Date: ${moment('#{openingDate}').format('YYYY-MM-DD')}</p>
Indeed that solved it. Thank you very much! This should be more clear in the docs