# Edit database table cell with text field

**URL:** <https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 2, 2025, 3:07pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590 "2025-04-02T15:07:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [April 2, 2025, 3:07pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/1 "2025-04-02T15:07:29Z")

</div>

Hello!

I would like to edit a DB from a text field in Perspective.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/7/57fd1444ed7b13768605c2af2f1d61e6cade8c67.png)

I already have a named query binded to the text field to show that value on Perspective.

I would like to edit this text field to upload the value on the DB.

The text field PROPS are:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/691c62287940463ac8aa76a57a860980756c5501.png)

And I add an onBlur event scriopt on the textfield:

```python
		
	new_kwlim_str = self.props.text
	codigo = self.getSibling("DNF-Code").props.text
	
	
	try:
	    new_kwlim = float(new_kwlim_str)
	    
	    system.db.runPrepUpdate(
	        "UPDATE T_SEDE SET KWLIM = ? WHERE CODIGO = ?",
	        [new_kwlim, codigo],
	        "DB-Name"  
	    )
	    
	    system.perspective.print("Updated KWLIM to " + str(new_kwlim) + " for CODE: " + str(codigo))
	    
	 
	
	      system.perspective.openPopup(
	        id="aprobar-popup",
	        view="Page/Aprobar",
	        params=popup_params,
	        title="Updated Successfully!",
	        modal=True,
	        width=400,
	        height=40
	    )
	
	
	except Exception as e:
	    system.perspective.print("Error updating KWLIM: " + str(e))
	    system.perspective.showNotification("Failed to update kW Lim.", "error")

```

I´m using the right DB-Name.

It doesn´t seem to work, I don´t see changes on the dB neither the notification

Maybe that kind of event is not the most suitable one for this case?

Any Idea what could be wrong with this aproach.

Thanks!

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 2, 2025, 3:12pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/2 "2025-04-02T15:12:43Z")

</div>

What is this, ` system.perspective.showNotification`?

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [April 2, 2025, 3:17pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/3 "2025-04-02T15:17:04Z")

</div>

Sorry about that, I updated the code with:

```python
  system.perspective.openPopup(
	        id="aprobar-popup",
	        view="Page/Aprobar",
	        params=popup_params,
	        title="Updated Successfully!",
	        modal=True,
	        width=400,
	        height=40
	    )

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 2, 2025, 3:29pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/4 "2025-04-02T15:29:22Z")

</div>

Why not use the NumericEntryField?

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [April 2, 2025, 3:32pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/5 "2025-04-02T15:32:12Z")

</div>

I adding kW into the textfield , but yes, in case I need it I can use a Numeric Entry Field,

do you think the script with event onBlur makes sense?

Cheers.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 2, 2025, 3:35pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/6 "2025-04-02T15:35:40Z")

</div>

It doesn't make sense to use a text field for a float. With the numeric entry, you can verify that the number entered is within certain bounds, that it is in fact a number, and it has an `onActionPerformed` event that can be triggered from direct, protected, or button modes.

The `onBlur` event does not guarantee that the user is finished editing the field.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [April 2, 2025, 3:47pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/7 "2025-04-02T15:47:31Z")

</div>

Thanks @dkhayes117 , I will try with the numeric field.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/8/080dec19e2c0bf623ed3b3c36e6403da7a7f20f5.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 2, 2025, 6:05pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/8 "2025-04-02T18:05:38Z")

</div>

> [@Alejandro\_Alaco](#):
>
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/7/57fd1444ed7b13768605c2af2f1d61e6cade8c67.png)

How are you going to compare a kW setting or reading with a database string? Keep the value and units separate in the database and in the user interface.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [April 2, 2025, 6:42pm UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/9 "2025-04-02T18:42:05Z")

</div>

The print in the except should have told you what went wrong. It should be printing something along the lines of "ValueError: Can't convert string to float".

Also, why an `onBlur` event ? Just put a button to validate the value. I would hate to have a value sent to a database just because I clicked outside of a field. Particularly if there's a confirmation popup !

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [April 3, 2025, 10:12am UTC](https://forum.inductiveautomation.com/t/edit-database-table-cell-with-text-field/104590/10 "2025-04-03T10:12:03Z")

</div>

Ok, thanks everibody, finally I used a Numeric Field with an onActionPerformed as @dkhayes117 suggested with this script:

```python
def runAction(self, event):
	import sys
	import traceback
	
	tr
		new_kwlim_raw = self.props.value
		codigo = self.getSibling("codigo").props.text.strip()
	
		
		new_kwlim = float(new_kwlim_raw) if new_kwlim_raw is not None else 0
	
		system.perspective.print("Actualizando KWLIM a {} para {}".format(new_kwlim, codigo))
	
	
		system.db.runPrepUpdate(
		    "UPDATE T_SEDE SET KWLIM = ? WHERE CODIGO = ?",
		    [new_kwlim, codigo],
		    "PSS"
		)
	
		system.perspective.openPopup(
		    id="success-popup",
		    view="Page/Aprobar",
		    params={"codigo": codigo, "kwlim": new_kwlim},
		    title="Updated Successfully!",
		    modal=True,
		    width=400,
		    height=40
		)
	
	except Exception:
		exc_type, exc_value, exc_tb = sys.exc_info()
		error_details = traceback.format_exception(exc_type, exc_value, exc_tb)
		
		for line in error_details:
		    system.perspective.print(line)
		
		system.perspective.openPopup(
		    id="error-popup",
		    view="Page/ErrorPopup",
		    params={"message": "Failed to update. See console for details."},
		    title="Error",
		    modal=True,
		    width=400,
		    height=100
		)
		

```

and it´s working fine.  
@Transistor I will show the units apart on a label, they don´t come from the DB I just added them and  
@pascal.fragnoud I will work on the interface so it´s clear the user is changing some value on the database and doesn´t cause trouble.
