question on calling a function on blur event for a field

  • 1
  • Question
  • Updated 3 years ago
  • Answered
Hi,

I have a field editor with 2-fields (UserName and Password)

Once the user enters a UserName in field, is there any way to call function (a web-service method which is in APEX that is actually calling an external service to check userExists or not)
without clicking on any button ?

Like if the focus is off that UserName field , can we make a function call to check if he exists already ?
Photo of KVin

KVin

  • 1,158 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
I'm not sure if this is what you are looking for, but you can set a model action that triggers when rows on model are updated, then set the field to UserName. When you pick what action to run, I believe you can choose run custom Apex as an action. Then every time the UserName field is updated it will trigger your custom Apex.
Photo of KVin

KVin

  • 1,158 Points 1k badge 2x thumb
Hey Raymond,

Thanks for the response!

Here is what I am trying to do :

When the UserName is entered, need to call a service to verify whether he/she exists in system already or not. 

The service returns some code (USER_FOUND / USER_NOT_FOUND)

Based on this return code, I need to display some error message below the UserName field itself,

for USER_FOUND : " The User Already exists, chose another username "
for USER_NOT_FOUND : Not error message but in green color below the field" Say like - UserName is Available. Please continue . . .  "

How should I approach for this case ?
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
That's pretty deep and beyond my capabilities. You'll have to wait for one of the super smart guys to respond. In the meant time you can check out Skuid's model services capabilities. You can probably create a model service to your external database and then pull it into a model, then interact with the model declaritively to accomplish what you want.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
With a custom renderer you are going to have full access to the DOM element and can tie code to the actions taken by the user.  So you could totally fire custom code on a "mouse out" event.  That's going to be custom code. 

The alternative Raymond is suggesting might be feasible without code. If you can access the external data source using a REST API,  you can set up a model action that fires when the UserName is updated. The action would set a condition on a model tied to the RESTAPI.  Then you could conditionally render a template with a message in it depending on the information returned into your REST API Model. 

Hopefully one or the other will get you going. 

Check out our tutorials for information on the Javascript API and on our REST Models.