Html element in markdown doesn't pass in correct key or keyCode value

in my separated js code:

function yell(e) {

    console.log("yell() ", JSON.stringify(e.value));

    console.log("yell() keycode ", e.keyCode, e.key);

    if (e.key === 'Enter' || e.keyCode === 13) {

        // Do something

    }

}

I would like to detect Enter is hit, but the e.key and e.keyCode do not have any value.
e.value has the value of textbox.

So how can I detect user hits Enter?

Hey @franva,
It seems like you’re trying to use Netlify CMS as a way to build a Javascript widget that would live-update as you code- that would be super cool, but it is not was the CMS was built for, so I would not expect that to work. The editor on the left only takes in text and images, and then renders them on the right with styling applied.

Let me know if this answers your question or if I misunderstood!

1 Like

thanks @jen yes, I thought the CMS could build not only text content but also html components.

It turns out, yes it can be used to add HTML components, but with limitations.

As a workaround, I have put my JS code in a separated js file and it works, so all good.

Thanks :slight_smile:

1 Like

Nice workaround :slight_smile: thanks for sharing

but the workaround does have a limitation.

Since I put the separated js file (helpers.js) under static folder, I cannot get process.env working over there, it throws error about undefined process.env.

If I moved the helpers.js under src folder, then the content of helpers.js is somehow replaced by html code.

see the details here:reactjs - Why is the content of my js file replaced by html code? - Stack Overflow

1 Like