Write-Backs Saving when Input Box Changes

I have a simple analysis app where we count the number of good/bad parts per layer. I’m pulling the number of good parts from each row and outputting that to a repeating panel. When I enter the # of bad parts, im using a onChange() to calculate the percentage.

The problem I’m having, is writing this to the row in the database.

I tried using an input box, and linking this to the DB then having it write back.

This WORKS, if I click in the percentage box AFTER it does it calculations. I tried doing an onChange() call for this input box, but didn’t seem to change anything.

I really need to call the parent and get the run number, then I could pass a filter to app.tables and update the table that way I think, but got to be an easier way.

Ideally, I’d like to change the Good Part % calculation back to a label, and just have that update the “Good_Part_Percentage” Row in the database when its calculated.

Just can’t think of a way to do that without pulling data from the parent to filter the app table call so I can update only the specific row.

I kinda got it working it seems.

added this to the lost focus calculation function:
self.item[‘Good_Parts_Percentage’] = float(getGoodPercentage)

And that does seems to write it to the database. Not sure if thats the best way to do it, but its much easier than having to pull data from PARENT.

  def text_box_good_parts_lost_focus(self, **event_args):
    """This method is called when the TextBox loses focus"""
    #Calculate the passing percentage once we lose focus of this box
    getGoodPercentage = (self.text_box_good_parts.text * 100) / int(self.label_Total_Parts_per_Layer.text)
    getGoodPercentage = "{:.2f}".format(getGoodPercentage)
    self.text_box_good_parts_percentage.text = getGoodPercentage
    #self.name_box.text = self.item['name']
    self.item['Good_Parts_Percentage'] = float(getGoodPercentage)

For what it’s worth, most people move away from using write backs to the database, since that requires that the data table be writable from the client, which opens up all sorts of security issues. Problems like you describe go away when you have to collate the data and send it to the server to update the database.

If I did that, would I pass the rowID to the server module to update the specific row? Or how would you write that we I’m making sure to update the row I need from the repeating panel.

I usually do all DB writing in server modules, but for this repeating panel the write-back was real simple solution to update a specific row.

Normally you pass a dictionary of changes, along with the original row or the row id. You can batch those by passing a list of dictionaries, to make a lot of updates at once (when the user presses the Save button, for example).

Write back is very simple, but be sure that you don’t mind the client having unrestricted write access to the table. Using a client writeable view can restrict the client to just those rows the user should be able to have unrestricted access to, and then you can still use the writeback. Just be sure you don’t have any columns in the table you don’t mind the user updating.