Is it possible to force set a value in ValidForm Builder? - validform

I have 2 sets of radio buttons. Is it possible in ValidForm Builder to set one instance of radio buttons to a certain value based on a conditional check against the other radio button?
// Radio List #1
$objRB1 = $objForm->addField('rb1', 'Radio Button #1', VFORM_RADIO_LIST,
array(),
array(),
array('default' => $default['rb1'])
);
$objRB1->addField('Red', 'R');
$objRB1->addField('Green', 'G');
$objRB1->addField('Blue', 'B');
// Radio List #2 -- NEED TO FORCE SET THIS TO "Delta" WHENEVER "Blue" IS SELECTED ABOVE
$objRB2 = $objForm->addField('rb2', 'Radio Button #2', VFORM_RADIO_LIST,
array(),
array(),
array('default' => $default['rb2'])
);
$objRB2->addField('Alpha', 'A');
$objRB2->addField('Delta', 'D');
$objRB2->addField('Omega', 'O');
How might that be done, if possible, in VFB?

ValidForm Builder conditions
ValidForm Builder has three conditions:
Visible
Enabled
Required
These three settings you can influence with conditions at the moment. Conditions don't change (default) values.
Workaround
A workaround would be to create two fields: one with value A as default value and one with value B as default value.
Then, you use a condition to trigger the visibility of both fields. When, on a third field, option A is chosen, only field A is visible with default value A. When option B is chosen, field B is shown (with the exact same label and values) but with value B as default value.
However, when implementing such a workaround, make sure you don't name field A and B exactly the same. Field names should always be unique.

Related

How to keep selected data persistent through callback in Dash/Plotly's clustered bar chart

I'm using Dash to plot some data. I currently have a clustered bar chart with two data sets (one for each bar in the clusters.) These data sets have their name and the corresponding color of the bars displayed in the top, left-hand corner of the figure. They can be clicked to be toggled on and off, which will remove their corresponding bars from the chart.
Separately, I have a checklist of items that can be displayed in the chart. I am using a callback to update the graph so that it only displays what the user has checked. This updates the graph as expected, however, it also resets the bars/datasets such that both are enabled. Ie. if you select only one of the bars, then select some new checklist items, it will display the new checklist items and both of the bars.
My thinking is that the logical way to do this is to pass some variable as a second input to the callback function, then set up the outputted figure within the function to only display the proper bars. However, I can't seem to find a variable that contains this data.
From what I can tell, the accessible properties of the Plotly graph object are 'id', 'clickData', 'clickAnnotationData', 'hoverData', 'clear_on_unhover', 'selectedData', 'relayoutData', 'figure', 'style', 'className', 'animate', 'animation_options', 'config', and 'loading_state'.
I've investigated all of these, and it seems that none hold the data that I am looking for. Does anyone know of an easy way to access this data?
This is how my callback is working right now:
#app.callback(
dash.dependencies.Output('theGraph', 'figure'),
[dash.dependencies.Input('theChecklist','values'),
dash.dependencies.Input('theGraph', 'clickData')
]
)
def updateGraph(checklistValues, figureInput):
#print to see what the variables hold
print(checklistValues)
print(figureInput)
figure=go.Figure(
data = [
go.Bar(
x = df[df['MyColumnName'].isin(checklistValues)].groupby('MyColumnName').size().index,
y = df[df['MyColumnName'].isin(checklistValues)].groupby('MyColumnName').size().values,
name = 'Bar 1'
),
go.Bar(
x = df[df['MyColumnName'].isin(checklistValues)].groupby('MyColumnName')['# cores'].sum().reset_index()['MyColumnName'],
y = df[df['MyColumnName'].isin(checklistValues)].groupby('MyColumnName')['# cores'].sum().reset_index()['MyOtherColumnName'],
name = 'Bar 2'
)
],
layout=go.Layout(
title='The Title',
showlegend=True,
legend=go.layout.Legend(
x=0,
y=1.0
),
margin=go.layout.Margin(l=40, r=40, t=40, b=110)
)
)
return figure

Listbox multiple selection matlab

I created a listbox and enabled multiple selections. My listbox contain numbers from 1 to 10. When I select 3, 1, and 8, the function always put my selections in alphabetical order (1,3,8). Is there any way I could make it not put my selection in alphabetical order? So if I select 3, 1, and 8 the output of my selection is 3, 1, 8.
Thank you.
For the purpose of this answer I'm assuming you're using matlab-hg2.
From the docs for uicontrol:
'listbox' ... The Value property stores the row indexes of currently selected list box items, and is a vector value when you select multiple items. After any mouse button up event that changes the Value property, MATLAB evaluates the list box's callback routine. To delay action when multiple items can be selected, you can associate a "Done" push button with the list box. Use the callback for that button to evaluate the list box Value property.
From the above we learn that the information on the selected lines is returned in Value. From there, it's a matter of keeping track of what's selected. This can be quite easily done using a persistent variable inside the listbox' Callback as shown in the following example:
function LISTBOX_EXAMPLE
hFig = figure('Units','Pixels','Position', [200 200 100 200],'Menubar','none');
uicontrol(hFig, ...
'Style', 'listbox',...
'Units','Pixels',...
'Position', [20 20 80 150],...
'Max',3,...
'Min',0,...
'String',num2cell(1:10),...
'Callback',#selectionCallback);
function selectionCallback(hObject,~)
persistent previouslyChosenItems
%// Elements were added:
if numel(previouslyChosenItems) < numel(hObject.Value)
previouslyChosenItems = union(previouslyChosenItems,hObject.Value,'stable');
%// Elements were removed:
elseif numel(previouslyChosenItems) > numel(hObject.Value)
previouslyChosenItems = intersect(previouslyChosenItems,hObject.Value,'stable');
%// A different element was selected (single element):
elseif numel(previouslyChosenItems) == numel(hObject.Value) && numel(hObject.Value)==1
previouslyChosenItems = hObject.Value;
end
disp(['Currently selected items (in order): ' num2str(previouslyChosenItems(:)')]);
end
end
Example output:
Currently selected items (in order): 7
Currently selected items (in order): 3
Currently selected items (in order): 3 9
Currently selected items (in order): 3 9 1
Then it's up to you to assign the value of previouslyChosenItems somplace useful.

Using several popupmenues different rows of a uitable

To generate a ui-table I'm using GUIDE. To insert a popup menu into the ui-table I'm using the following code(for example):
data = {1;2;3,'A';'B';'C'}
set(handles.uitable,'ColumnFormat',{'1','2','3'},'char',data)
Then i will get the same popup menu in every row of the ui-table.
But I want to have different popup menus in different rows of a ui-table, as shown in the picture below.
If I understood correctly, you want to set the 'ColumnEditTable' property of selected columns to true during the creation of your table, and depending of the columnformat you specify you can get popupmenus or checkboxes for example.. Consider this code, which I modified form the doc (look here)
function MyTable
f = figure('Position',[300 300 400 400]);
% Column names and column format
columnname = {'Greeting','Amount','Available','Fixed/Adj'};
columnformat = {{'Hello' 'Hi'},'bank','logical',{'Fixed' 'Adjustable'}}; %// Set the entries of the popup menu in a cell array. When the format is 'logical', the output in the table is a checkbox.
% Define the initial displayed data
d = {'Hi' 456.3457 true 'Fixed';...
'Hello' 510.2342 false 'Adjustable';...
'Hi' 658.2 false 'Fixed';};
% Create the uitable
t = uitable('Data', d,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', [true false true true],... %// That's the important line. Entries set to true will allow you to create a popup menu for the whole column.
'RowName',[]);
The table looks like this:
As you can see you can select 'Hi' or 'Hello' in the first columns and either 'Fixed' or 'Adjustable' in the last column.
Hope it gets you started and it's somewhat what you wanted!

WWW:Mechanize setvisible

Setting a radio button in the current form is simple:
$clone->set_visible([radio => '1']);
With an unknown number of radio buttons (probably 10 to 20) a loop should work:
while(1) {last if (!$clone->set_visible([radio => '1']));};
However, though setvisible always returns 1. My guess is it only returns 0 when nothing is set at all. But if even one field is set, it can get "re-set".
How do i stop after all radios are set? Or do i need to determine how many there are first?
You can find all inputs you need first:
my #radio_inputs = $mech->find_all_inputs(
type => 'radio',
);

Setting up some properties for a combobox (scroll, edit, jump)

There are 3 properties that I want to set for some VBA form comboboxes and I don't know if it's possible.
I don't want to let the combobox editable. Right now if the user types something in it that it submits the form it will send that value... I want to let him choose only from the values I added in the Combobox.
I want to make the list of items in the combobox scroll-able. Right now I'm able to scroll through the list if I use the scroll-bar but I don't know why I can't scroll with the mouse scroll.
And I want to jump to some item if I start typing. Let's say I have the months of the year in one combobox... if I start to type mar I want it to jump to march. I know that for the html forms this properties is by default but I don't know about VBA forms...
Thanks a lot
Of the behaviours you want, some are possible with settings on the Combo, others you will need to code
List of Months: Put a list of entries on a (hidden) sheet and name the range. Set .RowSource to that range
Match as you type: Set properties .MatchEntry = fmMatchEntryComplete and .MatchRequired = True
Reject non list entries: A Combo with these settings will allow you to type an invalid entry, but will reject it with an error message popup when you commit. If you want to silently reject invalid data as you type, you will need to code it.
If you want the selected value returned to a sheet, set .ControlSource to a cell address (preferable a named range)
By "...scroll with the mouse scroll..." I assume you mean the mouse wheel. Unfortunatley Forms don't support mouse wheel scroll. You will have to code it yourself. There is a Microsoft patch for this at here (not tried it myself yet)
Sample code to silently reject invalid entries
Private Sub cmbMonth_Change()
Static idx As Long
Dim Match As Boolean
Dim i As Long
If cmbMonth.Value = "" Then Exit Sub
If idx = 0 Then idx = 1
i = idx
Match = False
For i = 0 To cmbMonth.ListCount
If cmbMonth.List((i + idx - 1) Mod cmbMonth.ListCount) Like cmbMonth.Value & "*" Then
cmbMonth.ListIndex = (i + idx - 1) Mod cmbMonth.ListCount
Match = True
Exit For
End If
Next
If Not Match Then
cmbMonth.Value = Left(cmbMonth.Value, Len(cmbMonth.Value) - 1)
End If
End Sub
Set the propertie MatchEntry of combobox to 1 (fmMatchEntryComplete) and MatchRequired to true for example
combobox1.MatchEntry=1
combobox1.MatchRequired=True
[]'s