I have created a form and added an attribute as a Text widget in the Roam manager.
Now I'm trying to restrict the input to be an integer between 0 and 999. I want the field to stay "empty" (or "blanc") as long as the user enter a letter and only to accept integers (but not more that 3 digits). If a 4th digit is entered, the field should continue only showing the 3 first allowed digits.
In QGIS I was able to achieve this with QIntValidator (but QIntValidator is not "available" i Roam?):
global gangeField gangeField = myDialog.findChild(QLineEdit,"GANGE") # gangeField will only accept inntegers between 0 and 999 validator = QIntValidator(0, 999, myDialog.findChild(QWidget,"tab2enhet")) gangeField.setValidator(validator) gangeField.textChanged.connect(felt_onTextChanged) I have tried to add some Python (ver. 3.3.2) code in the __init__.py file, but only with limited success:
def accept(self): """ Called before the form is accepted. Override this and return False to cancel the accepting of the form. :return: """ # if ( int(self.boundwidgets['gange'].value()) == False ): # self.pushError("Angi integer!") if ( int(self.boundwidgets['gange'].value()) > 999 ): self.cancelload("Angi tall mellom 0 og 999") return True Alternative: Can I change the error message to view my personalized text (e.g."Gange must be a number between 0 and 999.") for 2 seconds (like the Warning that is visible for 2 seconds if a required field is missing)?
أكثر...
Now I'm trying to restrict the input to be an integer between 0 and 999. I want the field to stay "empty" (or "blanc") as long as the user enter a letter and only to accept integers (but not more that 3 digits). If a 4th digit is entered, the field should continue only showing the 3 first allowed digits.
In QGIS I was able to achieve this with QIntValidator (but QIntValidator is not "available" i Roam?):
global gangeField gangeField = myDialog.findChild(QLineEdit,"GANGE") # gangeField will only accept inntegers between 0 and 999 validator = QIntValidator(0, 999, myDialog.findChild(QWidget,"tab2enhet")) gangeField.setValidator(validator) gangeField.textChanged.connect(felt_onTextChanged) I have tried to add some Python (ver. 3.3.2) code in the __init__.py file, but only with limited success:
def accept(self): """ Called before the form is accepted. Override this and return False to cancel the accepting of the form. :return: """ # if ( int(self.boundwidgets['gange'].value()) == False ): # self.pushError("Angi integer!") if ( int(self.boundwidgets['gange'].value()) > 999 ): self.cancelload("Angi tall mellom 0 og 999") return True Alternative: Can I change the error message to view my personalized text (e.g."Gange must be a number between 0 and 999.") for 2 seconds (like the Warning that is visible for 2 seconds if a required field is missing)?
أكثر...