Perspective Text Field Numeric Keypad

After more work with this control I found a couple of significant areas for improvement.

First, I noticed that if you click on a number button then follow it by pressing the enter key it will repeat the last number. I was expecting that the enter key would post the message with the final value and close the form. This is a major shortcoming in my mind. I tried to fix this but found that the mouse click and enter generate the same onClick event and I could not find a way to distinguish betweeen the two. (see this post Button events - how to tell difference between mouse click and pressing enter). I'd really love to see a solution for this !

Second, I used the keypad popup on a numeric control in a template (using the VIsion terminology) that I repeated several times on another screen. Whenever I entered data into one numeric field it updated all the instances on the page !

The solution I devised was to create a unique id for each instance of the template by using the time the popup was opened (thanks to a suggestion I found on another post).

  • I added a custom property called "ownerID" to the numeric control
  • I modified the numeric control "onMouseDown" event to use the system.date.time.now() in milliseconds as a unique ID (this should be unique since there is usually only one mouse click at a time on a page):
	popupOpenedTime = str(system.date.toMillis(system.date.now()))
	self.custom.ownerID = popupOpenedTime
	owner = self.custom.ownerID
	popParams = {'owner': owner, 'min': self.props.inputBounds.minimum, 'max': self.props.inputBounds.maximum, 'oldValue': self.props.value, 'units': self.custom.keypad.units}	
	posit = None if self.custom.keypad.centerScreen else {'left': event.clientX, 'top': event.clientY}	
	system.perspective.openPopup('keypadPopup-' + owner, 'Exchange/Keypad/Numeric Popup', title=self.custom.keypad.title, params=popParams, position=posit, showCloseIcon=True, draggable=True, resizable=True, viewportBound=True, modal=True, overlayDismiss=True)
	
  • I modified the "keypadReturn" message handler on the numeric control to reference the "ownerID" now used in the payload
def onMessageReceived(self, payload):
	owner = self.custom.ownerID
	if owner == payload['owner']: