Trigger a script when user enters a number out of bounds

This is in Perspective. What I'm trying to accomplish is to trigger a popup when the user enters a number out of the acceptable range, informing them of the correct range. I have tried scripting on an event for the Numeric Entry, but I can't seem to get any of the methods to actually trigger in that scenario. I also tried a Property change script, but the problem is, if I enter a value out of range, at the time of script execution, the previousValue is "None" and the currentValue is actually the previous value that was in the box before. It's like, the object reverts the entry back and THEN runs the script. I need it to run the script BEFORE it does this. How do I do that?

Could you show us the script you already have written?

The Numeric Entry Field component has a built-in inputBounds.minimum and inputBounds.maximum properties which, when set, will disable the Apply button so the invalid value can't be entered in the first place.

There is also the inputBounds.invalidStyle section which allows you to apply a different style when an out-of-range entry is made. By default it sets the border to the --error theme color but with CSS you could alter that

I know about the style thing, and I'm using it, but the customer wants something more clear, and to tell the operator what the acceptable range is. My template view is pretty small, so the popup was one solution I've come up with. Are you saying there is no possible way to trigger a popup if an out of bounds value is entered? That seems like a MASSIVE shortcoming of Perspective, considering that Vision has this feature built in to its' object.

This is a property change script on the value property of the Numeric Entry:

    logger = system.util.getLogger("NumericEntryValidation")
	logger.info("=== SCRIPT STARTED ===")  # Check if script runs
	
	# Get value from event
	value = currentValue.value  
	prev = previousValue
	
	minimum = self.props.inputBounds.minimum
	maximum = self.props.inputBounds.maximum
	
	logger.info("Event triggered. New value = {}, Previous value = {}".format(
	    value, prev)
	)
	
	if value is not None and minimum is not None and maximum is not None:
	    if value < minimum or value > maximum:
	        logger.warn("Out of range! Value = {}, Min = {}, Max = {}".format(value, minimum, maximum))
	        
	        system.perspective.openPopup(
	            "msgPopup", 
	            "popup", 
	            {"message": "Value must be between {} and {}.".format(minimum, maximum)}
	        )
	    else:
	        logger.info("Value is valid: {}".format(value))
	else:
	    logger.error("Invalid input detected! Value: {}".format(value))

This is what I get on my logger when I enter values out of bounds. I entered 500, the limits are 0-362, but the script didn't catch it.

Also, before you say it, previousValue.value doesn't work if the result is None, so I had to strip that out just to get the script to work for now.

Steady on, Brian. I don't recall anyone mentioning this as an issue on the forums since Perspective's launch.

Did you try setting mode : button so that you get the data entry popup with the Cancel and Apply buttons. Its operation is very obvious.

1 Like

Sorry.

The customer wants the acceptable range displayed when they enter an out of bounds value. Yes, it tells you the entered number is out of bounds, but it doesn't tell you what the bounds are.

If you set its initial value to null, then you could use the placeholder to show the acceptable range:

image

Of course, that requires it to take up a fair amount of screen real estate. You could also use a tooltip, though I'm not sure that works on HMI screens.

I have run into this limitation myself and been frustrated by it.

You could also roll your own input using a standard Text Field. I did this when I needed better control over sizing and the functionality of the spinner buttons:

It uses a script to revert the value to its previous one if the user enters anything other than a digit, so such a script could also check the value and invoke a popup.

Thanks. That wouldn't really work since it's showing the current value right now. The issue is, this is an accepted, tested, and deployed system so making too radical changes could be an issue. Right now we're in the "tweaking" phase but it seems like their ask is a bigger deal than previously thought.

Ideally, I'd use the popup keypad on the Exchange, but the issue with that is, in order for that to be usable, you can't run the app in Kiosk mode, but you have to run the app in kiosk mode because there is no way to invoke a view from the login page. So I pretty much can't use the OSK because I'll have to shut off the operating system's OSK, which means nobody will be able to log in.