TOPIC: Set at false many checkboxes in a BrowseControl
#853
Set at false many checkboxes in a BrowseControl 3 Years, 3 Months ago
Hi, this is my problem: i have a table with a field 'predef' that it is used to show the default entry of this table.

I would like that when the user sets at true the checkbox field 'predef' of a row (inside a BrowseControl), all the other rows should be set at false. Only one row should have 'predef' field set at true.

I have done something like:

Code:

Controller
{
Controls:
#(Browse 'mytable')

Browse_AfterField(member, record)
{
if member is "predef"
{
QueryDo("update mytable where cod != '" $ record.cod $ "' set predef=false"')
}
}

}



It works but when I click on a checkbox the BrowseControl doesn't update the window to reflect the changes to the other rows.
I have tried to add '.Browse.BrowseControl_list.Repaint()' to the end of the method Browse_AfterField, but the checkboxes aren't updated...
There is an easy solution?

Post edited by: Mauro, at: 2007/04/26 18:17
 
 
Mauro
 
#854
Re:Set at false many checkboxes in a BrowseControl 3 Years, 3 Months ago
One solution is to update the browse records in memory.
Code:



Controller
{
Controls:
#(Browse 'mytable')

Browse_AfterField(member, record)
{
if member is "predef" and record.predef is true
for rec in .Browse.GetBrowseData()
if rec isnt record and rec.predef isnt false
rec.predef = false
}
}



This will update all other non-deleted records in the browse to false when a record's predef member is set to true.

Post edited by: jferguson, at: 2007/04/26 22:55
 
 
Jeff Ferguson
Suneido Software
 
#855
Re:Set at false many checkboxes in a BrowseControl 3 Years, 3 Months ago
Great Jeff, it works well! :)

I think it updates the checkboxes because there is an observer registered to the record returned by GetBrowseData(), right?
 
 
Mauro
 
#856
Re:Set at false many checkboxes in a BrowseControl 3 Years, 3 Months ago
You're right. There is actually an observer on each record in the browse that handles repainting the row when a field in the row changes. It also handles a bunch of other things like tracking if a record is dirty (needs to be saved to the database when the browse saves). Look at the Observer_ListRow2 method in BrowseControl. This is the observer method for each record in the browse.

If you want deleted records to be updated as well, you should be able to replace GetBrowseData with GetAllBrowseData.
 
 
Jeff Ferguson
Suneido Software
 
#857
Re:Set at false many checkboxes in a BrowseControl 3 Years, 3 Months ago
Thanks for the info! :)
 
 
Mauro