<div dir="ltr"><div><div><div>I am trying to write some form validation to work around <a href="http://hub.qgis.org/issues/15050">bug #15050</a>.  Based on some examples I have found I think this should work:<br><br>from PyQt4.QtCore import *<br>from PyQt4.QtGui import *<br><br>myDialog = None<br>notesField = None<br><br>def formOpen(dialog,layerid,featureid):<br>    global myDialog<br>    global notesField<br><br>    myDialog = dialog<br>    notesField = dialog.findChild(QPlainTextEdit,"Notes")<br>    buttonBox = dialog.findChild(QDialogButtonBox,"buttonBox")<br><br>    # Disconnect the signal that QGIS has wired up for the dialog to the button box.<br>    buttonBox.accepted.disconnect(myDialog.accept)<br>    # Wire up our own signals.<br>    buttonBox.accepted.connect(validate)<br>    #buttonBox.rejected.connect(myDialog.reject)<br><br>def validate():<br>    if notesField.document().characterCount() > 1000:<br>        msgBox = QMessageBox()<br>        msgBox.setText("Notes field must be <1000 characters")<br>        msgBox.exec_()<br>    else:<br>        myDialog.accept()<br><br></div>What happens is that I get the message box with the error, but when I click OK on the message box the form closes and saves anyway and I still lose text in the multiline field if it exceeds the field length.  How do I keep the form open to allow the user to fix the error(s)? <br><br></div>Thanks,<br><br></div>Andrew<br></div>