# 2 Input Fields for Username on Hosted Login Widget

**URL:** <https://devforum.okta.com/t/2-input-fields-for-username-on-hosted-login-widget/5357>\
**Category:** Questions\
**Created:** [June 10, 2019, 7:34pm UTC](https://devforum.okta.com/t/2-input-fields-for-username-on-hosted-login-widget/5357 "2019-06-10T19:34:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chu123](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/chu123/32/1816_2.png) [@chu123](https://devforum.okta.com/u/chu123)\
**Post date:** [June 10, 2019, 7:34pm UTC](https://devforum.okta.com/t/2-input-fields-for-username-on-hosted-login-widget/5357/1 "2019-06-10T19:34:12Z")

</div>

Hello,

Can I use the hosted login widget (with customizations) to have multiple input fields for authenticatoin? Moving from a legacy system, I need to bridge and have the username made up of two separate input fields (think: RegionID, UserID). I know I can use an event to merge these before they go to Okta (Okta will only see one combined username that is RegionID+UserID), but how can I get the input captured in 2 separate fields for the username?

---

<div class="post-metadata">

**Author:** ![dragos](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/dragos/32/1313_2.png) [@dragos](https://devforum.okta.com/u/dragos)\
**Post date:** [June 11, 2019, 11:16am UTC](https://devforum.okta.com/t/2-input-fields-for-username-on-hosted-login-widget/5357/2 "2019-06-11T11:16:29Z")

</div>

Hi @chu123

We do not have an out of the box integration for this scenario, however you can create a custom integration that would do the following operations:

- Take the username and password and verify them against the /api/v1/authn endpoint
- If the credentials are valid, the third field would be verified against a profile attribute that the user has
- If the profile attribute matches the third field, the user is allowed to log in

---

<div class="post-metadata">

**Author:** ![chu123](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/chu123/32/1816_2.png) [@chu123](https://devforum.okta.com/u/chu123)\
**Post date:** [June 11, 2019, 12:19pm UTC](https://devforum.okta.com/t/2-input-fields-for-username-on-hosted-login-widget/5357/3 "2019-06-11T12:19:01Z")

</div>

I don’t know that it needs to be even that hard? If I can just insert another text box (with the same Okta look’n’feel), I think I can just use `transformUsername: function (username, operation)` function to merge the two input fields, no?

---

<div class="post-metadata">

**Author:** ![chu123](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/chu123/32/1816_2.png) [@chu123](https://devforum.okta.com/u/chu123)\
**Post date:** [June 18, 2019, 4:58pm UTC](https://devforum.okta.com/t/2-input-fields-for-username-on-hosted-login-widget/5357/4 "2019-06-18T16:58:30Z")

</div>

Hello. I was able to solve by modifying the Custom Login Widget HTML code within the Okta Admin console. This was performed by basically having the following code:

```
  function sleep(ms) {
      return new Promise(resolve => setTimeout(resolve, ms));
  }

[...]

async function showPartnerID() {
     await sleep(400);
     var mydiv = document.getElementsByClassName("o-form-input-name-username o-form-control okta-form-input-field input-fix");
     mydiv[0].insertAdjacentHTML('beforebegin','<span data-se="o-form-input-username" class="o-form-input-name-username o-form-control okta-form-input-field input-fix o-form-has-errors"><span class="input-tooltip icon form-help-16" data-hasqtip="0"></span><span class="icon input-icon person-16-gray"></span><input type="text" placeholder="Partner ID" name="partner" id="okta-signin-username" value="" aria-label="User ID" autocomplete="off"></span>');
   }

[....]

window.addEventListener('load', function(){showPartnerID()}, false);

```

So basically there are 3 functions:

- Adding an event listener when the page loads (put this before `oktaSignIn.renderE`
- Find the HTML element with the UserName class and insert another form field above it
- Put in a “helper” wait for the page to load first (sleep 400ms)

I agree the UserName class search is probably not what I want - better to use the attribute name which is shorter and potentially more accurate.  
  ![capture](https://global.discourse-cdn.com/oktadev/original/2X/a/ad32a45fd46e9f9ae1312dca3d673085c4ac1f0f.png)

---

<div class="post-metadata">

**Author:** ![chu123](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/chu123/32/1816_2.png) [@chu123](https://devforum.okta.com/u/chu123)\
**Post date:** [June 20, 2019, 12:46pm UTC](https://devforum.okta.com/t/2-input-fields-for-username-on-hosted-login-widget/5357/5 "2019-06-20T12:46:08Z")

</div>

Just correcting my own post if someone else sees it - I switched from using the “window.AddEventListener” to just using the afterRender event. i.e.:

```
 oktaSignIn.on('afterRender', function(context) {
                showPartnerID();
            }

```

This avoids the sleep (which is non-compliant with all browsers and really, was just an amateur move on my part) and integrates properly with the way Okta UI wants it…

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [January 17, 2024, 11:41pm UTC](https://devforum.okta.com/t/2-input-fields-for-username-on-hosted-login-widget/5357/6 "2024-01-17T23:41:22Z")

</div>

Closed on January 17, 2024, 11:41pm UTC


