Keypad Entry Problem
All  1  2-6

Previous
Next
 From:  Michael Gibson
7012.2 In reply to 7012.1 
Hi Brian, yeah that's set up fairly differently than how regular MoI command scripts run. The usual method is to read values out of the input controls only once a UI event has been triggered, that's in the .js file where you have an event loop that does:

code:
	while ( 1 )
	{
		if ( !dialog.waitForEvent() )
                ....




You asked:

> Is there some way to let the keypad finish up, before the keys are grabbed?

Yeah it should be possible by waiting for the UI event for the input control to be triggered, and when that is received set a flag for the continuously updating loop to recalculate.

That would look something like this:

code:
		if ( dialog.event == 'done' ) break; // "Done" pushed.

		if ( dialog.event == 'U' )
		{
			// The input with id="U" has finished receiving input, characters have been typed and Enter
			// pushed or OK on the popup keypad has been pushed, now let an update happen.
                
			moi.ui.commandUI.SomeFlagForDoUpdate = true;
		}


Then on the .htm side make it look for the "SomeFlagForUpdate" variable and only let it go forward with processing things if that is set to true.


This kind of a thing with a constantly going script on a timer can be problematic with it trying to access the UI (with getting sort of "in between" values like this), if it's triggered more in response to UI events then that should probably help.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7012.3 In reply to 7012.1 
Hi Brian, also probably what is messing up your actual script is if you have characters like just a plain - or . as the text content in a NumericInput field, when you try to retrieve the .value property of that control you'll get the JavaScript 'undefined' value as the result rather than an actual number.

So another way to guard against this problem is to look if any of those fields have an 'undefined' value and bail out from further processing if that's the case.

That would be something like this:

code:
			function UpdateElastica()
			{
				if ( P.value === undefined || U.value === undefined || WD.value === undefined )
					return;


I think with this added in as the first line of the update function it should avoid your problem.

Before maybe your script is getting stuck in an infinite loop or something because it's expecting those values to be numbers but they're actually 'undefined'.

Please let me know if you still see any problems after adding this in.

- Michael

EDITED: 4 Nov 2014 by MICHAEL GIBSON

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
7012.4 In reply to 7012.3 
Thank you very much Michael.

Will try your answers.

I had tried NAN, which is incorrect :-)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7012.5 In reply to 7012.4 
Hi Brian, NaN was a good guess, but yeah 'undefined' is maybe a bit more universal which would maybe work with any kind of control even non-numeric stuff.

The other possibility was to throw an exception if you try to get the .value and there is no numeric representation of it... But that can be somewhat annoying to deal with as well.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  bemfarmer
7012.6 In reply to 7012.5 
Undefined works very well!

I have not observed any problems, so I will post _elastica2 under its topic.

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages: All  1  2-6