Issue with Complex UI Interaction and Event Handling

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sabrina23
Posts: 1
Joined: Wed Aug 21, 2024 4:36 am
Contact:

Issue with Complex UI Interaction and Event Handling

Post by sabrina23 » Wed Aug 21, 2024 4:45 am

I’m experiencing difficulties with managing complex UI interactions and event handling in my LiveCode application. The issue revolves around updating multiple UI elements dynamically based on user interactions and handling various events correctly.
I have a main interface with several buttons, fields, and custom controls. When a user interacts with one control, it should trigger updates across multiple other controls. However, these updates don’t always happen as expected.
I’m also trying to manage custom events triggered by certain actions. For example, when a user clicks a button, a custom event should be fired, and other parts of the script should respond to that event. Sometimes the event handlers don’t fire correctly or seem to conflict with other events.
UI Updates: Sometimes the UI elements don’t update as expected. For example, the "Submit" button may not disable or enable properly, or the text in fields might not update as intended.

Code: Select all

-- Button click handler
on mouseUp
   -- Update UI elements
   set the enabled of btn "Submit" to false
   set the text of field "Status" to "Processing..."

   -- Trigger a custom event
   send "updateStatus" to me
end mouseUp

-- Custom event handler
on updateStatus
   -- Some complex logic to update multiple fields
   set the text of field "Result" to "Updated"
   set the enabled of btn "Submit" to true
end updateStatus

-- Another event or action
on someOtherEvent
   -- Handling other events
   -- This sometimes conflicts with the custom event
end someOtherEvent
Event Handling: The custom event updateStatus doesn’t always execute as expected, and sometimes conflicts with other events. This causes inconsistencies in the UI and makes the application behave unpredictably.
Are there best practices for managing complex UI updates and ensuring that multiple UI elements are updated consistently based on user interactions?
How can I avoid conflicts between custom events and other events in LiveCode, and ensure that event handlers execute as intended?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Issue with Complex UI Interaction and Event Handling

Post by dunbarx » Wed Aug 21, 2024 2:11 pm

Hi.

Welcome to the forum.

I made a small test stack, and found something interesting. Although the word "submit" is not in the dictionary, it seems to be reserved by LC, and cannot be processed under script control. I changed the name of that button to 'submittt", and all worked just fine.

This is not the first time this has happened. There are many native words in LC that are not documented. You found one.

Craig

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 166
Joined: Tue Feb 23, 2010 10:53 pm

Re: Issue with Complex UI Interaction and Event Handling

Post by bobcole » Thu Aug 22, 2024 4:27 pm

Maybe adding a "wait with messages" command after updating the fields/buttons would help.
Bob

Code: Select all

wait 1 millisecond with messages

Code: Select all

-- Button click handler
on mouseUp
   -- Update UI elements
   set the enabled of btn "Submit" to false
   wait 1 millisecond with messages. -- ADDED
   set the text of field "Status" to "Processing..."
   
   -- Trigger a custom event
   send "updateStatus" to me
   wait 1 millisecond with messages. -- ADDED

end mouseUp

-- Custom event handler
on updateStatus
   -- Some complex logic to update multiple fields
   set the text of field "Result" to "Updated"
   set the enabled of btn "Submit" to true
   wait 1 millisecond with messages. -- ADDED
end updateStatus

stam
Posts: 3092
Joined: Sun Jun 04, 2006 9:39 pm

Re: Issue with Complex UI Interaction and Event Handling

Post by stam » Thu Aug 22, 2024 4:31 pm

My inclination is to wait for the OP to chime in again.
The cynical part of me sees AI-generated code which suggests this may possibly not be a genuine post.
But I am overly cynical so would wait to hear from the OP.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Issue with Complex UI Interaction and Event Handling

Post by dunbarx » Thu Aug 22, 2024 5:19 pm

Stam.

I see what you mean, reading the script comments, about likely AI, but the handlers themselves are clean and accurate. If AI, then pretty good.

The OP has an issue though, and I do not see it. That is what should come next.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Issue with Complex UI Interaction and Event Handling

Post by dunbarx » Thu Aug 22, 2024 5:23 pm

Bob.

Waiting notwithstanding, did your button "submit" actually disable? Mine would not, and only on a hunch did I change its name to see what would happen.

Craig

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 166
Joined: Tue Feb 23, 2010 10:53 pm

Re: Issue with Complex UI Interaction and Event Handling

Post by bobcole » Thu Aug 22, 2024 5:42 pm

Yes, my "Submit" button did disable itself. It all happens very quickly so it is hard to see.
Try putting a "wait 1 second" command before the enable statement in the updateStatus handler to see it in operation.
Bob

Code: Select all

-- Custom event handler
on updateStatus
   -- Some complex logic to update multiple fields
   set the text of field "Result" to "Updated"
   wait 1 second --TRY THIS
   set the enabled of btn "Submit" to true
end updateStatus


stam
Posts: 3092
Joined: Sun Jun 04, 2006 9:39 pm

Re: Issue with Complex UI Interaction and Event Handling

Post by stam » Thu Aug 22, 2024 5:52 pm

dunbarx wrote:
Thu Aug 22, 2024 5:19 pm
I see what you mean, reading the script comments, about likely AI, but the handlers themselves are clean and accurate. If AI, then pretty good.
That's roughly been my experience with AI when I last tested a few months ago, although it would occasionally confabulate. Perhaps they've improved their models now. But regardless, it would return a well structured response with helpful comments to guide.

ChatGPT is becoming much better place to search for answers than google, that's for sure.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Issue with Complex UI Interaction and Event Handling

Post by dunbarx » Thu Aug 22, 2024 6:20 pm

Bob.
Try putting a "wait 1 second" command before the enable statement in the updateStatus handler to see it in operation.
Nope, only NOT using the name "submit" for that button allows it to be disabled.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10054
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Issue with Complex UI Interaction and Event Handling

Post by FourthWorld » Thu Aug 22, 2024 6:51 pm

dunbarx wrote:
Thu Aug 22, 2024 6:20 pm
Nope, only NOT using the name "submit" for that button allows it to be disabled.
How could the engine differentiate by a string literal?

I suspect there's something else in play there.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Issue with Complex UI Interaction and Event Handling

Post by dunbarx » Thu Aug 22, 2024 8:28 pm

You know, it must be that "forest for the trees thing". Here: :oops:

The handler "update Status" resets the enabled of btn "submit". That is why, wait just a second, :oops: changing the name only in the mouseUp handler worked, because I did not change the name in the "updateStatus" handler.

One more time; :oops:

I noticed something was amiss since now and then I saw the btn "submit" flash momentarily, and I looked around for some cause. So that was all a waste of time, hopefully mainly for me.

As for Sabrina, I (now) see nothing wrong with anything in your post. Forget everything I said about reserved words. :oops:

Craig

Post Reply