so there is a script that came embedded with a form creator that I have and once you click Submit (verifies all boxes have data and writes to SQL) it then clears the contents of all of the boxes ready for new input, this is good but I want a couple of the items to remain.
see script below ( as you can see it has been provided as a template to use)
“”"
Information about the Form Components Palette can be found here:
http://nickmudge.info/post/database-driven-forms-in-ignition
This Python module and the Form Components Palette was created by Nick Mudge,
from Perfect Abstractions (http://www.perfectabstractions.com).
Contact me (Nick Mudge) if you want me to add more functionality.
Otherwise add more functionality yourself 
Copyright (c) 2014, Nick Mudge (nick@perfectabstractions.com)
All rights reserved.
Redistribution and use of this source code, with or without modification, are permitted
provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
“”"
from java.awt import Color
from com.inductiveautomation.factorypmi.application.components
import BasicContainer, PMITextField, PMITextArea, PMITable, PMIComboBox, PMINumericTextField
from com.inductiveautomation.factorypmi.application.components
import PMIDateTimePopupSelector, PMIRadioButton
class FormInput:
“”"
This class provides a uniform interface to form input components.
“”"
numericModes = {0:"intValue",1:"longValue",2:"floatValue",3:"doubleValue"}
def __init__(self, inputContainer):
self.input = inputContainer
def validate(self):
"""
Form input components have a "validateInput" method that validates input.
"""
if hasattr(self.input, "validateInput"):
self.input.validateInput()
def IsValid(self):
if hasattr(self.input, "IsValid"):
return self.input.IsValid
else:
return True
def getColumn(self):
return self.input.Column
def getFormInput(self):
return self.input
def getValue(self):
"""
Different form input components have different ways to get its value.
"""
for comp in self.input.getComponents():
if isinstance(comp, (PMITextField,PMITextArea)):
return comp.text
elif isinstance(comp, PMINumericTextField):
mode = FormInput.numericModes[comp.mode]
return getattr(comp, mode)
elif isinstance(comp,PMIComboBox):
return getattr(comp,comp.ValueProperty)
elif isinstance(comp,PMIRadioButton):
if comp.selected:
return comp.text
system.gui.messageBox("No form input found.")
def clearValue(self):
for comp in self.input.getComponents():
if isinstance(comp, (PMITextField,PMITextArea)):
comp.text = ""
elif isinstance(comp, PMINumericTextField):
for prop in FormInput.numericModes.values():
setattr(comp,prop,0)
elif isinstance(comp,PMIComboBox):
comp.selectedValue = -1
comp.selectedStringValue = ""
elif isinstance(comp,PMIRadioButton):
if comp.text == "Default":
comp.selected = True
def func():
invalidMessage = self.input.getComponent("InvalidMessage")
if invalidMessage != None:
invalidMessage.visible = False
system.util.invokeLater(func)
def setValue(self,value):
for comp in self.input.getComponents():
if isinstance(comp, (PMITextField,PMITextArea)):
if value == None:
value = ""
comp.text = value
elif isinstance(comp, PMINumericTextField):
if value == None:
value = 0
mode = FormInput.numericModes[comp.mode]
setattr(comp,mode,value)
elif isinstance(comp,PMIRadioButton):
if value in ["",None]:
value = "Default"
if value == comp.text:
comp.selected = True
elif isinstance(comp,PMIComboBox):
if value == None:
if comp.ValueProperty in ["selectedStringValue","selectedLabel"]:
value == ""
elif comp.ValueProperty == "selectedValue":
value = -1
setattr(comp,comp.ValueProperty,value)
def updateFormInputs(table):
“”"
Update form input components after a form is submitted or a row is
selected to be edited in a Form Table.
“”"
tableContainer = table.parent
formContainer = tableContainer.parent
tableColumns = set(table.data.getColumnNames())
row = table.selectedRow
inputs = getInputs(formContainer)
submitButtons = getSubmitButtons(formContainer)
if row == -1:
buttonText = “Submit”
tableContainer.getComponent(“Add Button”).enabled = False
tableContainer.getComponent(“Delete Button”).enabled = False
for input in inputs:
input.clearValue()
else:
buttonText = “Update”
tableContainer.getComponent(“Add Button”).enabled = True
tableContainer.getComponent(“Delete Button”).enabled = True
for input in inputs:
if input.getColumn() in tableColumns:
input.setValue(table.data.getValueAt(row,input.getColumn()))
for submitButton in submitButtons:
submitButton.getComponent(“Button”).text = buttonText
def getSubmitButtons(formContainer):
“”"
Get all for submit buttons in a form container.
“”"
submitButtons =
for comp in formContainer.getComponents():
if isinstance(comp,BasicContainer):
if not hasattr(comp,“IsSubmitButton”):
submitButtons.extend(getSubmitButtons(comp))
continue
submitButtons.append(comp)
return submitButtons
def getFormTables(formContainer):
“”"
Get all form tables in a form container.
“”"
tables =
for comp in formContainer.getComponents():
if isinstance(comp,BasicContainer):
if not hasattr(comp,“PrimaryKeyColumn”):
tables.extend(getFormTables(comp))
continue
tables.append(comp)
return tables
def deleteRow(tableContainer):
formContainer = tableContainer.parent
tableName = formContainer.TableName
table = tableContainer.getComponent(“Table”)
values = [table.data.getValueAt(table.selectedRow,tableContainer.PrimaryKeyColumn)]
query = “DELETE FROM %s WHERE %s=?”% (tableName,tableContainer.PrimaryKeyColumn)
if formContainer.Datasource == “”:
system.db.runPrepUpdate(query,values)
else:
system.db.runPrepUpdate(query,values, formContainer.Datasource)
system.db.refresh(table,“data”)
def submit(event):
“”"
A form is submitted. Perform validation and if input is good either
submit form data or update form data.
“”"
submitContainer = event.source.parent
status = submitContainer.getComponent(“Status”)
def hideValidationStatus(): status.visible=False
formContainer = submitContainer.parent
inputs = getInputs(formContainer)
for input in inputs:
input.validate()
if not inputsValid(inputs):
status.text = “Validation Error”
status.foreground = Color(217,0,0)
status.visible = True
system.util.invokeLater(hideValidationStatus,1500)
return
status.visible = False
#print getInsertQuery(submitContainer, inputs)
columnsAndValues = {}
for input in inputs:
columnsAndValues[input.getColumn()] = input.getValue()
row = -1
ID = None
primaryKeyColumn = “”
formTables = getFormTables(formContainer)
if len(formTables) > 0:
tableContainer = formTables[0]
table = tableContainer.getComponent(“Table”)
row = table.selectedRow
primaryKeyColumn = tableContainer.PrimaryKeyColumn
if row > -1:
ID = table.data.getValueAt(row,primaryKeyColumn)
columns = “,”.join(“%s=?”% column for column in columnsAndValues.keys())
query = “UPDATE %s SET %s WHERE %s=?”% (formContainer.TableName, columns, primaryKeyColumn)
values = columnsAndValues.values() + [ID]
else:
columns = “,”.join(columnsAndValues.keys())
questionMarks = “,”.join([“?”] * len(columnsAndValues))
query = “INSERT INTO %s (%s) VALUES (%s)”% (formContainer.TableName, columns, questionMarks)
values = columnsAndValues.values()
if formContainer.Datasource == “”:
system.db.runPrepUpdate(query,values)
else:
system.db.runPrepUpdate(query,values, formContainer.Datasource)
status.foreground = Color(0,128,0)
status.text = “Success”
status.visible = True
tableContainers = getFormTables(formContainer)
for tableContainer in tableContainers:
system.db.refresh(tableContainer.getComponent(“Table”), “data”)
system.util.invokeLater(hideValidationStatus,2000)
if row == -1:
for input in inputs:
input.clearValue()
def getInputs(formContainer):
“”"
Get all form input components in a Form Container.
“”"
inputs =
for comp in formContainer.getComponents():
if isinstance(comp,BasicContainer):
if not hasattr(comp,“Column”):
inputs.extend(getInputs(comp))
continue
inputs.append(FormInput(comp))
return inputs
def inputsValid(inputs):
“”"
Check if input is valid for all form input components.
“”"
for input in inputs:
if not input.IsValid():
return False
return True