# Is there a way to Prevent Default for only certain keys

**URL:** <https://forum.inductiveautomation.com/t/is-there-a-way-to-prevent-default-for-only-certain-keys/115420>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 6, 2026, 9:14pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-prevent-default-for-only-certain-keys/115420 "2026-05-06T21:14:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![travisaggiebrown](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/travisaggiebrown/32/85824_2.png) [@travisaggiebrown](https://forum.inductiveautomation.com/u/travisaggiebrown)\
**Post date:** [May 6, 2026, 9:14pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-prevent-default-for-only-certain-keys/115420/1 "2026-05-06T21:14:38Z")

</div>

I want to make it where if I press enter in a text box in a form it will exit it, but upon making a onKeyPress event I have realized that I don't think there is a way to prevent default for specific keys that are pressed?

Wondered if anyone knew a way before I resorted to "exploiting" with a JS injection

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 7, 2026, 1:25pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-prevent-default-for-only-certain-keys/115420/2 "2026-05-07T13:25:53Z")

</div>

> [@travisaggiebrown](#):
>
> I have realized that I don't think there is a way to prevent default for specific keys that are pressed?

Not sure I understand what you mean by "prevent default".

Is the desire to have an onKeyPress event that only looks for the Enter key?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 7, 2026, 3:02pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-prevent-default-for-only-certain-keys/115420/3 "2026-05-07T15:02:52Z")

</div>

> [@travisaggiebrown](#):
>
> "exploiting" with a JS injection

Just note that IA will be removing this ability with the Markdown component in a future version

---

<div class="post-metadata">

**Author:** ![travisaggiebrown](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/travisaggiebrown/32/85824_2.png) [@travisaggiebrown](https://forum.inductiveautomation.com/u/travisaggiebrown)\
**Post date:** [May 7, 2026, 7:17pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-prevent-default-for-only-certain-keys/115420/4 "2026-05-07T19:17:19Z")

</div>

I want the OnKeyPress to only prevent the keystroke of enter.

So on the press of enter instead of adding a newline to the text box I want it to ignore then enter keypress and focus outside the text box.

When you use the prevent default on the event it makes it where it prevents all keystrokes which makes you unable to type in the text box.

---

<div class="post-metadata">

**Author:** ![travisaggiebrown](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/travisaggiebrown/32/85824_2.png) [@travisaggiebrown](https://forum.inductiveautomation.com/u/travisaggiebrown)\
**Post date:** [May 7, 2026, 7:18pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-prevent-default-for-only-certain-keys/115420/5 "2026-05-07T19:18:49Z")

</div>

yeah, I have heard. I built a module for when that day comes, but I will continue to use markdown injections out of spite till that day.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 7, 2026, 7:31pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-prevent-default-for-only-certain-keys/115420/6 "2026-05-07T19:31:53Z")

</div>

> [@travisaggiebrown](#):
>
> So on the press of enter instead of adding a newline to the text box I want it to ignore then enter keypress and focus outside the text box.

Do you have `props.deferUpdates` set to `true`? This will make the enter button fire the update to the component rather than, having it update on each key press.

---

<div class="post-metadata">

**Author:** ![travisaggiebrown](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/travisaggiebrown/32/85824_2.png) [@travisaggiebrown](https://forum.inductiveautomation.com/u/travisaggiebrown)\
**Post date:** [May 7, 2026, 8:41pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-prevent-default-for-only-certain-keys/115420/7 "2026-05-07T20:41:56Z")

</div>

okay, I may have been a little confusing with my words. it's not a text component it's a form component with a widget of the type text so it doesn't have a defer update option.
