# Want to switch from one text field to password field by pressing enter

**URL:** <https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 26, 2025, 5:33pm UTC](https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858 "2025-06-26T17:33:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![owaisurrehman786](https://avatars.discourse-cdn.com/v4/letter/o/958977/32.png) [@owaisurrehman786](https://forum.inductiveautomation.com/u/owaisurrehman786)\
**Post date:** [June 26, 2025, 5:33pm UTC](https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858/1 "2025-06-26T17:33:24Z")

</div>

i am making a login form in which my root container is a flex container.

- in root i have added two more flex containers
- in first flex container i have the text field
- in second flex container i have the password field
- i want to do is that when i press enter key in text field
- it will move to the password field
- both the components are in the same view
- but in different flex containers

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 26, 2025, 5:38pm UTC](https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858/2 "2025-06-26T17:38:42Z")

</div>

Tip: Standard GUI is that Enter triggers the default button - probably the Login or similar in your view. (And Esc triggers the Cancel button.)  
You should be aiming to move to next field with Tab.

I think you're looking for `.focus()`. I haven't had to do it so I can't help further at this time.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [June 26, 2025, 6:16pm UTC](https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858/3 "2025-06-26T18:16:17Z")

</div>

Use on `onKeyPress` event handler on the text field, and then `.focus()` on the password field:

```python
{
  "custom": {},
  "params": {},
  "props": {},
  "root": {
    "children": [
      {
        "events": {
          "dom": {
            "onKeyPress": {
              "config": {
                "script": "\tif event.key \u003d\u003d \u0027Enter\u0027:\n\t\tsystem.perspective.sendMessage(\u0027focus-pwd\u0027)"
              },
              "scope": "G",
              "type": "script"
            }
          }
        },
        "meta": {
          "name": "TextField"
        },
        "position": {
          "basis": "32px"
        },
        "props": {
          "placeholder": "Hit ENTER to..."
        },
        "type": "ia.input.text-field"
      },
      {
        "meta": {
          "name": "PasswordField"
        },
        "position": {
          "basis": "32px"
        },
        "props": {
          "placeholder": "...focus this field"
        },
        "scripts": {
          "customMethods": [],
          "extensionFunctions": null,
          "messageHandlers": [
            {
              "messageType": "focus-pwd",
              "pageScope": true,
              "script": "\tself.focus()",
              "sessionScope": false,
              "viewScope": false
            }
          ]
        },
        "type": "ia.input.password-field"
      }
    ],
    "meta": {
      "name": "root"
    },
    "props": {
      "direction": "column",
      "style": {
        "gap": 8,
        "padding": 8
      }
    },
    "type": "ia.container.flex"
  }
}

```

You can paste that example into a new view by holding down SHIFT while right-clicking and selecting "Paste JSON." It uses a message to notify the password field rather than navigating to the field via `getSibling()` as that kind of code breaks as soon as you start renaming/reorganizing components (and should be easier to plug in to whatever layout you already have).

---

<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:** [June 26, 2025, 10:05pm UTC](https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858/4 "2025-06-26T22:05:28Z")

</div>

Just checking you're not trying to roll your own user login?

---

<div class="post-metadata">

**Author:** ![owaisurrehman786](https://avatars.discourse-cdn.com/v4/letter/o/958977/32.png) [@owaisurrehman786](https://forum.inductiveautomation.com/u/owaisurrehman786)\
**Post date:** [June 28, 2025, 8:37pm UTC](https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858/5 "2025-06-28T20:37:21Z")

</div>

Thanks that .focus() solved the issue but i did it in a different way.  
i just simply moved from that text field to the password field by writing in textField event action onKeyPressed script:  
if event.key == "Enter":  
self.parent.parent.getChild("FlexContainer\_0").getChild("passwordField").focus()

my textField was in a flex container and the passwordField was in a different flex. both were in the same view.

---

<div class="post-metadata">

**Author:** ![owaisurrehman786](https://avatars.discourse-cdn.com/v4/letter/o/958977/32.png) [@owaisurrehman786](https://forum.inductiveautomation.com/u/owaisurrehman786)\
**Post date:** [June 28, 2025, 8:38pm UTC](https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858/6 "2025-06-28T20:38:46Z")

</div>

i was making my own login but the problem has been solved

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 28, 2025, 11:07pm UTC](https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858/7 "2025-06-28T23:07:57Z")

</div>

> [@owaisurrehman786](#):
>
> `self.parent.parent.getChild("FlexContainer_0").getChild("passwordField").focus()`

This sort of code breaks if you ever move components in and out of containers or rename them.

Consider using `sendMessage()` instead and adding a message handler on the target field to set focus on itself. This is a practice worth adopting and whoever has to maintain your code will appreciate it.

Also, please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [June 30, 2025, 2:10pm UTC](https://forum.inductiveautomation.com/t/want-to-switch-from-one-text-field-to-password-field-by-pressing-enter/107858/8 "2025-06-30T14:10:50Z")

</div>

Seriously, what @Transistor said. It took me a while to get in the habit, but lately I'm soooo glad I did, as I've been able to revamp several different layouts without worrying about what I might have broke in the process. I now bind the value of every input to a custom view property, so I can reference that instead of the input itself. It not only safeguards it against layout changes, but makes for much cleaner, easier to understand code (I cringe every time I see a `.getChild()` or `.getSibling()`). Just a little extra effort in the short term can save you lots of hassle in the long run.
