76
Views
14
Comments
Solved
How to: OnChange event with list input

Hello,

I have a block that consists of a list element with several inputs. The block has an event "ChangedInput" which is triggered in the OnChange event of each input.

The event has an input variable in which the changed data is stored. The type of the variable is a (structure) list.

On Change of the inputs:



In the parent screen the stored data is called with a Fetch data aggregate called GetFalls(...): 

The list of this aggregate is assigned to the input variable ListeFall of the block : 

In the On Change FaelleChangedInput I assign the changed data to my original data in the database:


the problem is: while filling out the input fields the mouse focus stops after every key stroke. I assume it's because of the event the list is somehow automatically reloaded and it looses focus.

I also tried the onblur event as an alternative. The problem with that solution: if the users types in input 1 and finishes by clicking on input 2 the onblur is fired and focus is lost again. The user needs to click in input 2 again to start typing. This is not ideal.

I've also tried my approach in another block that just has a record instead of a list. Everything works fine, so it must have something to do with the list.

The problem is also described here: https://www.outsystems.com/forums/discussion/85451/onchange-event-input-widget-inside-list-widget/ but that didn't really help.

Thanks for your help!

Greetings

2025-05-02 20-28-47
Drishti Menghani
Solution

Hi,

Also I have seen your OML, there's a better way to do that. Instead of triggering on change, you should trigger the event on add button, which you are having.

Attaching the changed OML, please check this. Made changes in the below block only.


It's working as expected.


Test_InputOnChangeWithList1.oml
UserImage.jpg
Cassandra Zimmermann

this definitely worked but doesn't fit my use case completely. Maybe with a separate icon as some kind of checkmark that "stops" the editing mode. With the OnChange on the Add button I always need to add a new (empty) item to the list to trigger the change of the previous one. Because in this case I don't want such a additional button I used the local list to save my changes

2025-05-02 20-28-47
Drishti Menghani
Solution

Hi @Cassandra Zimmermann,

You are using GetFaelle.List as input of the block and again as soon as you type you are triggering on Change event with the same structure list and assigning back to GetFaelie.List, and again the list is passed to the block because it's been changed. Causing infinite looping between GetFaelle.List assignment and passing changed list to block, making it loose the focus as new value been passed to the input widgets. 

A quick possible Solution:

Create a Local List with the same structure let's say LocalFaelleList and on change event handler use the LocalFaelleList to assign value instead of GetFaelle.List, that's how you would prevent the unwanted changing loop. And use the LocalFaelleList as final one.


Hope this will help you!!


UserImage.jpg
Cassandra Zimmermann

yes this worked, thank you!

UserImage.jpg
Alexandru Gaidau
Solution

@Cassandra Zimmermann i think i understand what you are trying to do now. Here are a few considerations. The focus JS will not work either as once the list is rerendered in on parameters changed the elements will have different ids. you could techically save in a local variable the index of the element then on parameters changed look for the element at that index and get the new id and only then use focus on it. but this makes little to no sense to do at all. avoid changing the input list. once you notify parent do NOT reassign the input list. instead use a new variable to store the list that the child sends. this will make more sense. or do not use a nested block for this at all and you could modify the dataaction result if need be

UserImage.jpg
Cassandra Zimmermann

yes this worked, thank you!

2023-02-19 05-11-08
Faais

Hi Cassandra Zimmermann,  
Try using onBlur instead of onChange.


UserImage.jpg
Cassandra Zimmermann

Hi!

like I've mentioned I already tried the onBlur event. It works for the input that was just typed in. But if the user wants to go to the next input they need to double click. First click triggers the OnBlur of the first input and it looses focus on the 2nd input. So they need to click into input 2 again to type in that field.

Any idea how I can prevent the double click?

Thx!

2023-02-19 05-11-08
Faais

Is it possible to share the OML? It will be easier to debug. 

UserImage.jpg
Cassandra Zimmermann

see attached test-oml with the different variations. Thank you!

Test_InputOnChangeWithList.oml
2023-03-24 11-55-45
Pawan Purohit

Hi,

Can you try with the onFocusOut event?

If you're using JavaScript, focusout bubbles up and can help you detect focus changes more gracefully

Hope it helps you.

Thanks



 

UserImage.jpg
Cassandra Zimmermann

unfortunately I don't seem to have such an event

I then tried typing it manually in the event field but my event "ChangedData" isn't triggered. 

UserImage.jpg
Alexandru Gaidau

@Cassandra Zimmermann if i understand correctly you just aim to get that field to be preselected. to achive that use the outsystemui > setfocus action. you pass in the widget id and it will focus on it. hope that helps

UserImage.jpg
Cassandra Zimmermann

it shouldn't be like "auto-/pre-selecting" a specific input field. The user can decide whcih field they want to fill out next. What I want in short form:

  • User can fill out an input field without being interrupted by lost focus (this currently happens due to On Change in List) and
  • if user selects the next input field to fill out they shouldn't need to double click that field (this currently happens when I use the onBlur event)

see .oml that I attached in this comment: https://www.outsystems.com/forums/discussion/102901/how-to-onchange-event-with-list-input/#Post451236


Or ist there another way to use a List with input fields in a block that doesn't disturb the user experience?

Thanks!

UserImage.jpg
Alexandru Gaidau
Solution

@Cassandra Zimmermann i think i understand what you are trying to do now. Here are a few considerations. The focus JS will not work either as once the list is rerendered in on parameters changed the elements will have different ids. you could techically save in a local variable the index of the element then on parameters changed look for the element at that index and get the new id and only then use focus on it. but this makes little to no sense to do at all. avoid changing the input list. once you notify parent do NOT reassign the input list. instead use a new variable to store the list that the child sends. this will make more sense. or do not use a nested block for this at all and you could modify the dataaction result if need be

UserImage.jpg
Cassandra Zimmermann

yes this worked, thank you!

2025-05-02 20-28-47
Drishti Menghani
Solution

Hi @Cassandra Zimmermann,

You are using GetFaelle.List as input of the block and again as soon as you type you are triggering on Change event with the same structure list and assigning back to GetFaelie.List, and again the list is passed to the block because it's been changed. Causing infinite looping between GetFaelle.List assignment and passing changed list to block, making it loose the focus as new value been passed to the input widgets. 

A quick possible Solution:

Create a Local List with the same structure let's say LocalFaelleList and on change event handler use the LocalFaelleList to assign value instead of GetFaelle.List, that's how you would prevent the unwanted changing loop. And use the LocalFaelleList as final one.


Hope this will help you!!


UserImage.jpg
Cassandra Zimmermann

yes this worked, thank you!

2025-05-02 20-28-47
Drishti Menghani
Solution

Hi,

Also I have seen your OML, there's a better way to do that. Instead of triggering on change, you should trigger the event on add button, which you are having.

Attaching the changed OML, please check this. Made changes in the below block only.


It's working as expected.


Test_InputOnChangeWithList1.oml
UserImage.jpg
Cassandra Zimmermann

this definitely worked but doesn't fit my use case completely. Maybe with a separate icon as some kind of checkmark that "stops" the editing mode. With the OnChange on the Add button I always need to add a new (empty) item to the list to trigger the change of the previous one. Because in this case I don't want such a additional button I used the local list to save my changes

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.