Is there a way to block everthing other than numeric values from be entered in to a power tables column?
If you just want to prevent the edit from going through, you can check the
newValue in the
onCellEdited extension function and throw an error to the user if the value was invalid.
If you want to be really fancy and provide a warning while the user is entering the value, then you’ll need to implement the
configureEditor extension function and return a custom editor. It’s a non-trivial operation that requires a decent working knowledge of Java Swing. There’s some code samples on the forum for various editor implementations.
Is there a way on the onCellEdited function to set the value back to a blank entry if the script below sends the gui message?
#test to stop text from being entered in to the Reading column if colName == "Reading": results = 0 try: results = int(newValue) except: system.gui.messageBox("You must enter a Numeric Value")
onCellEdited, no. The editor has already tried to commit by that point.
You’d have to implement your own
TableCellEditor for that. The JDK supplies a default implementation that can use a text field as the backing: DefaultCellEditor (Java SE 11 & JDK 11 )
I was able to accomblish it this way with the onCellEdited Function, below is the script I used. I didn’t end up using the gui message, I just put some text that states the error and then cleared it out.
#test to stop text from being entered in to the Reading column if colName == "Reading" and newValue != "": results = 0 try: results = int(newValue) except: self.parent.getComponent('ReadingValueError').visible = True def writeLater(): self.parent.getComponent('ReadingValueError').visible = False system.util.invokeLater(writeLater, 3000) # If row and column have been selected, update value in table to "" newData = system.dataset.setValue(self.data, rowIndex, colIndex, "") self.data = newData