web2py SQLFORM.factory defaults not updating - forms

I have an SQLFORM.factory on a page that I use to(among other things) update a particular field in a table. That field is a drop down table I made like so
Field('visibility',requires=IS_IN_SET(['everyone','subscribers','friends','nobody']))
So the field in the SQLFORM.factory looks the same. The difference is that I want the default in the SQLFORM.factory to be the current value of that field in a particular table. by making a default. I do a query on the desired entry on the table, select that field, and that becomes my default, the selected option. Perfect the first time you load it up.
I do the update after the form accepts like so and the update works functionally:
if subForm.accepts(request,session,dbio=True):
if myForm.vars.visible != theDefault:
db(row).update(visibility = subForm.vars.visibility)
If you submit the page the selected option is not the current value of that field in the table, it's always the one it was previous. If I look at my database admin the table updated fine but I could not fetch the right option to select as my default. If my default was 'everyone' and then I select and submit 'friends' then the selected when the page reload after the submit is still 'everyone' If I then select and submit 'nobody', after the refresh it is 'friends'.
If it helps, I am displaying the view this SQLFORM.factory is in in and iFrame as part of a bigger page.

After many hours, here's how you do it(sorta hackey but it works)
#This is a kludge to get the right default visibility selected
if request.vars.visible == None:
visibleDefault = theDefault
else:
visibleDefault = request.vars.visible
form = SQLFORM.factory(
FIELD(Field('visible',requires=IS_IN_SET(['everyone','subscribers','friends','nobody'],zero=None),default=visibleDefault),
table_name='table')
if form.accepts(request,session,dbio=True):
if form.vars.visible != theDefault:
db(row).update(visibility = form.vars.visible)

Related

Update chart after changing a field in an APEX form

How do I cause APEX to refresh a chart (graph) after I change the value in a text box/select list/etc that is used as a parameter in the chart's pl/sql statement?
I'd like it to look as professional as possible and minimize the portion of the page that must be refreshed (i.e., "ajax-like", which is the standard in 2018).
Create a dynamic action on the text box/select list/etc that is changed with event "change"
Create a true action and select pl/sql and write
Begin
null;
end;
In page items to submit select your items
Create a second true action after the first and select Refresh. Then select region as affected element and select your chart. Remember that the option 'Fire on initialization' must be set to NO
See Approach B, below, for the optimal solution.
Approach A
The simplest option (that is less professional) is to modify every text box/select list/etc of interest to submit the page when the value of the text box/select list/etc changes. As an example, for the select list, go to its settings->page action on selection and change the setting to submit page.
There are two main downsides to that approach:
Most of the page will refresh, which is jarring to your user, and
If you're using a plugin, or the type of item that you're using doesn't support that approach, then you're out of luck.
Approach B
A more complex solution that yields a more professional result follows. This solution involves dynamic actions, which I will probably not fully explain here. However, the information should be enough for the user to figure it out.
Let us suppose that you have two things: (1) a select list whose value is used as a parameter in a (2) chart's sql source statement.
To get the chart to update every time you make a new choice via the select list, you need to:
Create a dynamic action for the select list of interest. You do this by clicking on the select list, going to the dynamic action tab (the lightning bolt); right-click on the item; click select dynamic action; give it a name and set the event to change and make the selection type an item and set the item to the name of the select list you're watching.
Create a true action for that dynamic action that executes pl/sql code (you can do this by modifying the show action that was created by default in 1.). Set the pl/sql code to null;. Then under items to submit, specify the name of the select list of interest.
Create a second true action that refreshes the region that contains the chart.
You'll need to make sure that the sequence assigned to 2. is a smaller number than the sequence assigned to 3.. This should happen by default, but it's an area you can get tripped up.
Inapplicable Approach C
In Apex 5.something, they added a feature called Cascading List of Values. This feature allows you to specify that one item depends on another item for its values. For example, if you have a select list that allows the user to choose a department, and then you have a second select list that allows you to choose an employee from the chosen department (which presumably obtains its values from a query involving the value chosen in the first select list), you can tell APEX to refresh the second select list whenever you update the first.
You do this by editing the second select list. Under its settings goto list of values->cascading LOV parent item(s). Add the first select list as a "reverse" dependent (aka, "parent"). This will ensure that any time the first select list is updated, the second select list is also updated.
For better or for worse, charts do not have the cascading LOV parent item(s) setting. Thus, this solution does not apply to this question.

Before Update Event or After Update Event (MS Access 2013)

I develop small database which gets bigger every day and I've got a situation with Before Update Event on one field.
Let's say I have main form which has subform based on the table (PONSt). The subform has one specific field (PONSt_PDV) which data depends on the other table (APP_PDV). When user updates that field (PONSt_PDV) directly in combo box, Before Update events is triggered and some calculations are done. That works perfectly!
The second situation (which is the reason for this question) is when user double clicks that combo box to open pop up form which contains the data from the other table (APP_PDV). In that pop up form user can edit, add or delete it's data and everything works great. There is a button on that pop up form which is used to get data (ID) from that table (APP_PDV), store it to the first table's field (PONSt_PDV), close the pop up form and get back to the first form (sub form on the first form, to be exact). After that, I want to recalculate other fields (in the first table PONSt) depending on the change in field (PONSt_PDV), but Before Update (or After Update) event in that case doesn't trigger at all.
What I'm doing wrong? Is there something that I can't see? Thanks!

oracle apex 4.2 : populate a form when page is loaded

How can I populate the form when the page is loaded
I have tried an query base form, and a automatic fetch, but neither will display any data when the page loads.
You must create "Automated Row Fetch" process on the page. For each item on page change the "Source Type" to "Database column", and enter column name in "Source value or expression".
When using the page wizard to create a query based form, the query given in the wizard is only used to define the fields on the form and create the corresponding page items. It is not used to subsequently populate data.
For that you need to add a process in a region above/before your form. Make the process PL/SQL type and provide your query there. Assuming your form is on page 2 and has fields ID and Name, use:
select name into :P2_NAME from my_table where id = :P2_ID;
The page or link that calls page 2 will need to set the value for P2_ID.

How to set a look up field value to null/blank in access 2010?

I need some help with Access 2010 forms. My form has a number of fields (from one table). One of the field is a logical field. If the user selects true, then the next field (text field) should be enabled. This is working fine - I created an after update event procedure. The problem I have is if the user accidentally selects true, and then selects a value/s for the text field (the text field looks up a query - it is a look up field and it can have more than one value - the user can select/check as many from the list and they will be stored to the text field, separated by coma).
How will I set the text field (look up field) value to blank, if the user goes back and set the logical field to false? me.textfield.value = null gives an error.
Can anyone please help me? Thank you!
Just keep in mind that in fact a multi-value column is in fact a normalized data table.
So the display looks like this:
To clear the records selected in this child table, which is your mult-value selection, you can use this code behind the above button:
Dim rstChild As DAO.Recordset
Set rstChild = Me.Recordset.Color.value
Do While rstChild.EOF = False
rstChild.Delete
rstChild.MoveNext
Loop
Me.Color.Requery
An easy way to insert a blank lookup field is to select the field in design view and click on the lookup tab in the field properties. Before the first entry in Row Source insert the following " ";

Access comboxbox selection needs to change value in label control

On a form, I have a combobox, with the RowSource coming from a query (specifically, a calculated field in the query). When the user makes a selection, I want to update a label on the same form with a different column from that same query, but of course associated to the selection.
I'm fine with VBA and writing queries and whatnot, but I am not very familiar with Access forms.
By the way, I tried searching for an answer to this, but it was quite difficult because I don't know what this thing is really called that I am trying to do. A good link to a site explaining this would be perfectly fine (no need to write a bunch of stuff here if it already exists elsewhere).
In the After Update event of my combo box, cboUserID, I can set a label control, lblFoo, to the value of the second column in the selected row of the combo.
Me.lblFoo.Caption = Me.cboUserID.Column(1)
If your combo box is bound to a field in the form's record source, you may want to do that same operation from the form's On Current event also.
You can use the column property to refer to anything other than the bound column of a combo.
Rowsource: SELECT ID, SName, FName FROM Table
Me.MyCombo.Column(2)
This would return FName.
-- http://msdn.microsoft.com/en-us/library/aa224084(v=office.11).aspx
Me.MyLabel.Caption = Me.MyCombo.Column(2)