How to force a widget (dropdown box) value programmatically? - bokeh

I'm setting in place a visualization which data are driven by selections made through bokeh widgets (mainly dropdowns).
The dropdowns are linked (i.e: depending on dropdown 1 choice, dropdown2 will be filled with certain data, etc...)
I have 2 needs which tend to be the same:
I know I can get the value of a choice by using dropdown1.value (in an on_change callback) so:
How can I set the value of a dropdown (and force it to display this choice) ?
How can I reset all dropdowns to the default startup position?
Thanks for the help!

The Bokeh Dropdown widget doesn't support displaying the value that you clicked. You would need to use Select widget for that.
Then like bigreddot already said there is no tracking of default value but if you put your "default" value as first in the options attribute of your Select then you can do:
select.value = value to select/display a value
select.value = null (JS callback)
or
select.value = None (Python callback) to select/display the first value

In JavaScript, or Python:
widget.value = new_value
There's nothing that keeps track of the initial values you set. You will have to record them and set them as above when you want them to reset.

Related

In App Maker, can you fake valueIsRecord with a dropdown field?

In App Maker, what is the simplest way to achieve the same result with a dropdown box that you can with a suggest box, which can return the whole record when you make a selection giving you the ability to assign associated record values to other fields on the page?
Consider a data model with three fields, (Code, Description, and Severity). Add a dropdown box to select the Code. Have the selection, (probably using onValueChange or onValueEdit), write the selected Code's Description to a label field beside the dropdown box. The Code's Severity will also be used to affect the style in some way like background color or something, but for this answer, merely assigning the value to a scripting variable will be good enough. It's the record value access and assignment mechanism I am after.
Clarification: This data model will not be the page's datasource. It is a secondary reference table used for assigning a code to a ticket. You can also assume that a record value will be written to a field in the page's datasource as well.
I would appreciate the simplest low code solution as we will have non-programmers attempting this. Thanks.
As long as you leave your value binding on the dropdown blank the following should work:
Set the options binding to:
#datasources.YourDatasource.items
You may want to consider changing the 'Names' binding to be the projection of a particular field in this datasource otherwise the values showing in your dropdown will only be the 'keys' from this datasource.
Then in your onValueEdit event you will gain access to individual fields like this:
var item = widget.datasource.item;
item.YourFieldToEdit1 = newValue.YourOtherDatasourceField1;
item.YourFieldToEdit2 = newValue.YourOtherDatasourceField2;
That would probably be the simplest way.

Google App Maker not reocognising some of its own widgets

In Google App Maker, I have several widgets on a page.
One of these widgets is called Label12 (shown in Screenshot 1).
It definitely exists and is also shown in the breadcrumb trail at the top of my screen.
However, when I attempt to reference Label12 in my code, it does not seem to exist.
If I use the ctrl+space code completion helper, the Label12 widget is not shown as an option (shown in screenshot 2).
When I attempt to code it manually (e.g. app.pages.Reconciliation_Details.descendants.Label12.visible) it returns the error "Cannot set property 'visible' of undefined".
Why can App Maker not see Label12?
Screenshot 1 showing Label12 on page:
Screenshot 2 showing absence of Label12 when coding:
App Maker can see Label12. The point is that the label is inside a table widget, hence according to the documentation:
Because a table is a collection of other widgets, you can't use the Widget API to interact with a table. However, you can use scripts to manipulate the individual widgets that make up a table.
The above statement makes sense because the amount of rows a table will display depends on the datasource items; i.e., the rows are dynamically created when the widget datasource is loaded in the ui. Therefore, in order to access the label you need to first access the children of the Table1Body, which is a collection of named values known as PropertyMap.
I believe you are trying to hide/show that specific label based on some logic. The correct way of doing it would be something like this:
var rows = app.pages.Reconciliation_Details.descendants.Table1Body.children._values;
for(var i=0; i<rows.length; i++){
var row = rows[i];
var label = row.descendants.Label12;
label.visible = true; // or false
}

Return value of another field within model

I have a model with two fields, Name and Token. In my app, the user will select a record from a Dropdown populated with the Name field of all records. When this happens, I need to assign the record's corresponding Token value to a variable in a server script, but am not sure how to accomplish this.
There are two options that are suitable. As a first option you could implement a server script that returns the token of the field when you edit the widget.
function checkToken(widgetValue) {
var query = app.models.YourModel.newQuery();
query.filters.Field._equals = widgetValue;
var records = query.run();
return records[0].Token;
}
You can add the script caller checkToken(widget.value) to the onValueEdit event of widget, so that it runs every time you select another dropdown item. If you want to use another event, please look at https://developers.google.com/appmaker/ui/logic#events.
As a second option you could add a secondary label to your form which you bind to the dropdown item selection. The binding would look something like this:
#pages.MyPage.descendants.DropDown.value.Token
When you configure Dropdown you need to set three important properties:
options
An array of string representations of options that makes up the content of the dropdown
#datasources.MyDatasource.items..Token
names
An array of strings to be displayed in place of options' default strings. The array must be the same length as options.
#datasources.MyDatasource.items..Name
value
The value assigned to the databound property, based on the user's dropdown selection
// Assuming that dropdown is added to form
// or any other container bound to proper datasource.
#datasource.item.Token
Note
double dot .. syntax is used for projections

Showing all the possible values of a field in App Maker dropdown

I need to create a filter which gets all the possible values for a concrete field, but I'm only getting the values which appears in the current page.
Result
What can I do to get all the values?
It looks like you want to filter table basing on value in the dropdown. In order to do this you need to bind your dropdown's value to datasource's filter:
#datasources.MyData.query.filters.Country._equals
then you need to reload your datasource every time when user changes dropdown's value
// onValueEdit
app.datasources.MyData.load();
You can play with this sample app to learn more: https://developers.google.com/appmaker/samples/project-list/

VFP Grid with multiselect

I'm trying to implement multiple record selection feature on a grid.
It is very similar to http://www.tek-tips.com/faqs.cfm?fid=3831
It adds an extra column with check boxes. I want those check boxes!!
But it depends on a extra logical field in the underlying table. It need to create a class clscheck which inherits CHECKBOX. I'm not sure why this CLICK procedure is needed for the checkbox.
PROCEDURE CLICK
IF DODEFAULT()
KEYBOARD '{DNARROW}'
ENDIF
ENDPROC
When I removed it, row selection did not work correctly as expected. Why this?
Here is my requirement:
1) I don't want to add an extra logical field in the underlying table.
2) To work with controls in the grid, I think AllowCellSelection must be .T. I want AllowCellSelection = .F. because I don't need to work with any control in the grid except the check boxes. I need to work only with check boxes. The other columns will be read-only.
3) Can I have selected list without the logical field in the underlying table?
4) Can I remove the usage of KEYBOARD '{DNARROW}'?
In fact, I have a grid which is AllowCellSelection = .F., but it only provides single selection.
I need to enhance it with multiple selection, thus, I just want to add an extra column with check boxes so that user can know he can select multiple records.
No need Shift+Click or Ctrl+Click which is not familiar with idiot users.
I have found this - http://www.tek-tips.com/faqs.cfm?fid=433
It also depends on an extra logical field and it depends Shift+Click and Ctrl+Click.
What you are seeing is quite common for multi-select grids. I've used them SIMILAR to this in the past. However, you are afraid of the extra column in the underlying table. That may/not be true. You don't always have to update the ORIGINAL table, but a temporary CURSOR you are presenting to the user. Ex: If you want to display a list of employees in a table. No, you don't want to keep adding this column to the original employee table as then anyone else trying to do multi-select could falsely get your selection. However, if you pulled into your own local cursor and presented to the user, then no problem. Example...
Thisform.YourGrid.RecordSource = "Employees"
(bound directly to your employee table -- not necessarily the right thing)
vs
use in select( "C_MultiPickEmployees" )
select ;
.F. as IsChosen, ;
E.* ;
from ;
Employees E;
into ;
cursor C_MultiPickEmployees READWRITE
Thisform.YourGrid.RecordSource = "C_MultiPickEmployees"
NOW, you have your extra column without dealing with issues to the underlying table. If you wanted to further filter what you were showing -- such as employees for a certain division/department, then just add that to a WHERE clause, add an Order By if so needed and you are good to go.
As for the "Allow Cell Selection", I've never had to deal with that. I just add a "checkbox" to the first column and set
Thisform.YourGrid.Column[1].CurrentControl = "CheckBoxControl"
(based on the name it is added to the column).
Then, set the column 1's "ControlSource" = "C_MultiPickEmployees.IsChosen" and you should mostly be done.
As for the "CLICK" event trying to force the down arrow. This is more for automatically scrolling to the next record so you can just click, click, click for multiple entries.
Hope this helps clarify things for you.

Resources