Checkboxes on Perspective Forms - No initial value?

I’m trying to use the Form component to add a record to a database table I’ve created.

I think I’ve got it working, with the exception of two boolean fields.

I initially tried using toggle switches. When the form loads, the switches are in the Off position. If I change them to On, the data is recorded as True. If I toggle them twice (Off → On → Off), the data is recorded as False. But if I never toggle them, I get an error message:

Caused by: java.lang.Throwable: Incorrect integer value: 'undefined' for column 'active' at row 1

I’m running into a similar issue using checkboxes. Strangely, the checkboxes don’t seem to register the first time I click them, but after that, it’s essentially the same issue.

I’ve tried testing for “togglevalue is None,” but this doesn’t seem to help.

Digging through the properties of the form components, I don’t see a way to explicitly initialize the value of the toggle switches or checkboxes.

Any thoughts would be appreciated. I’m new to Ignition / Python / Jython, so I AI’d the scripting, but I’ve been programming databases longer than I care to admit.

Here’s a portion of the script I’m using, simplified for brevity.

	...
	active = data.get("Active", False)
	obsolete = data.get("Obsolete", False)
	...
	if active is None: active = False
	if obsolete is None: obsolete = False
	...
	query = """
	INSERT INTO tbl (
		id, description, 
		active, obsolete
	) VALUES (
		?, ?, 
		?, ?
	)
	"""
	
	args = [
		id,
		description,
		active,
		obsolete
	]
	
	rows = system.db.runPrepUpdate(query, args, "ign") 

I may be missing something in your post but try this:

  • Give the checkbox widget an id. In my quick check it was
    columns.items.0.rows.items.4.widgets.0.id : chkbox0
  • Then in the root of the PROPS add the following property and setting.
    data.widget.chkbox0 : false

The form data is readable and writeable in the data.widget section.

It appears that if you don't specify id names that the form data shows up as 0:, 1:, etc., but you don't really know which is which.

That worked, thank you!

1 Like