If I edit a field with type GPLong, and then edit a field with a filtered drop-down menu, the numerical field clears/reverts to the previous value. If I edit the first field, press tab or click the background, and then edit the drop-down field, the edits stay.
I observed this with a custom tool and a default Pro tool. It does not appear to happen if you go directly from a numerical to a text field, or a text field to a filtered field.
Is this something that can be "fixed", or is it an unavoidable part of how parameter inputs get validated?
I'm afraid I might not be explaining clearly enough so I will write it like a table too:
- type in numerical field ✗ numerical field does not keep update | - type in numerical field ✓ numerical field does keep update | - type in numerical field ✓ numerical field does keep update | - type in text field - click directly on a filtered field ✓ text field does keep update |
Thanks - Sam
Hard to say without your parameter declarations and update conditions.
My favorite workaround is to build a dictionary of parameters and store it in a class variable then call an update function whenever the update function runs.
self.params = dict(zip([(p.name, p) for p in parameters]))
maybe using that at the top of your updateParameters function will help you debug in your execute. If the value in the object parameters (self.params) differs from the parameter value passed to the execute function, then it means something in your update function is causing issues
Hi Hayden, thanks for your suggestion. I might not have been clear enough but I was encountering this while still editing the tool not after running. So I believe it is all within updateParameters(), if it is in our code at all. I'll look into the changes you suggested.
However, we have now found that the behavior seems to only occur in version 3.1.x. Therefore we are treating it as a likely ArcGIS Pro bug rather than an error in our code. (I'll update this post for any future visitors if I hear back about the bug report.)
Just ran a test and wrote the parameter values out to a warning message as they changed. You're definitely correct that it seems Esri introduced some sort of focus bug on the element for number inputs.
The value isn't written into the parameter until focus is lost, but with the number field, it seems that changing focus to any other parameter input box clears the focus without then writing the value to the parameter.
For now, a good workaroud might be to have numeric parameters defined as 'GPString' with this updateParameters() check:
def updateParameters(self, parameters: list) -> None:
self.params = archelp.get_params(parameters) # Replace this with index
if self.params["number"].altered:
if not self.params["number"].valueAsText.isnumeric():
self.params["number"].setErrorMessage("Number must be numeric")
self.params["number"].value = None
return