cyclotron icon indicating copy to clipboard operation
cyclotron copied to clipboard

dataSource value passed to moment function does not render properly

Open RaphiStein opened this issue 5 years ago • 2 comments

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')}

RaphiStein avatar Apr 09 '19 03:04 RaphiStein

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>

baumandm avatar Apr 09 '19 14:04 baumandm

Indeed that solved it. Thank you very much! This should be more clear in the docs

RaphiStein avatar Apr 18 '19 15:04 RaphiStein