Red vid How focus changed from one field to another with press enter - red

View [
f1: field focus
f2: field
]
When run this code cursor get focus in f1
But I want to press enter and focus will be in f2.
How can I do that?

From inside a on-enter handler, you need to change the selected facet of the window face (just the parent face in this case) to point to the face you want to focus on. So your code becomes:
view [ f1: field focus on-enter [face/parent/selected: f2] f2: field ]
If you need to change focus often, you can define a convenient shortcut function:
set-focus: function [face [object!]][
p: face/parent
while [p/type <> 'window][p: p/parent]
p/selected: face
]
view [ f1: field focus on-enter [set-focus f2] f2: field ]
Red/View will provide a built-in set-focus function in future versions, so you won't have to define it in your own code.

Related

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

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.

How do i scroll a UITable view down until i see a cell with label "Value" in Calabash

How do i scroll a UITableView down until i see a cell with label "Value" in Calabash/Cucumber.
I've been trying to do it using:
Then I swipe down until I see "Value"
and using:
Then I scroll down until I see "Value"
but none of them seem to work. Thanks!
The message I get when I try with the above is obviously:
You can implement step definitions for undefined steps with these
snippets:
Then(/^I swipe down until I see "(.*?)"$/) do |arg1| pending #
express the regexp above with the code you wish you had end
add step definitions
Then /^I scroll to cell with "([^\"]*)" label$/ do |name|
wait_poll(:until_exists => "label text:'#{name}'", :timeout => 20) do
scroll("tableView", :down)
end
end
to the ProjectName/features/step_definitions/my_first_steps.rb ruby file and
In your calabash script add
Then I scroll to cell with "AAA" label
its working fine for me.
Every cucumber framework has a set of predefined steps. Of course, these steps don't cover all the possibilites. If you need additional functionality, you have to define your own steps:
When /^I scroll (up|down) until I see "([^\"]*)"$/ do |direction, something_to_see|
#implement the step here
end
I can't help you with the exact implementation (what is "Value"?) but you can find the core functions here
Probably you'll need function
scroll(uiquery, direction)
(where uiquery will be tableView)
If you take this function and element_is_not_hidden you can create a while cycle which will scroll down until you see the "Value".
Maybe something similar to the following (I don't know Calabash but I know Frank a little)
When /^I scroll (up|down) until I see "([^\"]*)"$/ do |direction, something_to_see|
max_scroll_tries = 10
[0..max_scroll_tries].each do
break if element_is_not_hidden("view marked:'#{something_to_see}'")
scroll("tableView", direction)
end
check_element_exists_and_is_visible("view marked:'#{something_to_see}'")
end
table have rows and sections, based how your code is organized use rows or sections in below code
def scroll_side_panel(text)
section=0
scroll_to_cell(:row => 0, :section => 0) # scroll to top of view
sleep 1 # wait for a second
#Scroll to each element and compare text, if there is a match break
each_cell(:animate => false, :post_scroll => 0.2) do |row, sec|
puts "#{query("tableViewCell indexPath:#{row},#{sec} label", :text)} #{text}"
if query("tableViewCell indexPath:#{row},#{sec} label", :text).first==text
break
end
section=section+1
end
puts "table view text found at element number:#{section}"
end
following should also work
Then(/^I scrolldown until "(.*?)" is visible$/) do |arg1|
until query("lable text:'#{arg1}'").length > 0
scroll("tableView", :down)
end
end
Call this by following
Then I scrolldown until "XY" is visible

Comparing Turtle Color In Netlogo

I am trying to do something I imagine is relatively simply but for some reason I am having a heck of a time figuring it out and all my searches are turning up blank.
I want to query the color of a specific turtle and check if it matches another color. I want to do something like this:
if color targetTurtleNum = red [set target-confirmed true] ;
But I keep getting an error:
IF expected this input to be a command block, but got a true/false instead.
Any ideas?
Assuming targetTurtleNum is the "who" number of the turtle you are interested in, try:
if [ color ] of turtle targetTurtleNum = red [ set target-confirmed true ]
The error you are getting is because if expects two inputs: a boolean (the condition you want to check) and a command block (what to do if the condition is true). In your version of the code, the first input thatif is getting is color, and the second one is targetTurtleNum = red, so the compiler complains about getting a boolean as the second input.
In the correct version up here, the whole [ color ] of turtle targetTurtleNum = red part is the boolean that counts as the first input, and [ set target-confirmed true ] is the command block that is expected as the second input.

Selecting a different record in List View via Script

I have a table in Filemaker 11 which has fields: thingID, infoNumber (#), itemHistory. infoNumber displays the order in which we think the item history's happened (sometimes this is incorrect and needs to be rearranged).
thingID, #, itemHistory
Thing 1, 1, was with Adam
Thing 1, 2, was with Claire
Thing 1, 3, was with Ben
Thing 1, 4, was with Dave
I display these in a List View (ordered by infoNumber asc), and a user realises that it actually went "1,3,2,4", I want to have up and down arrows visible in order for users to switch them, i.e. clicking on the up arrow on the record with infoNumber=3 will set it to 2 and the old infoNumber=2 will be set as 3.
How can I write a script to switch these when the user clicks on a button in a list view?
My idea:
Set Variable[$clickedDown, infoNumber] #the record we click on's infoNumber
If [ $clickedDown != 1 ]
Set Field [ infoNumber, clickedDown -1 ]
# But how do I move to the record with infoNumber = clickedDown-1 ??
End If
The way I have done this, is to do several Finds, here is my solution for going one way.
# First you've clicked on something, record its current infoNumber
Set Variable [ $infoNumber, infoNumber ]
# Use -2 (arbitrary) as a temporary place holder
Set Field [ infoNumber = -2]
Error Capture [ On ]
Perform Find [ thingID = $thingID, infoNumber = $infoNumber - 1 ]
If [ Get (LastError = 401) ]
# No results then just re-search temporary and set it back to what it
was
Perform Find [ thingID = $thingID, infoNumber = -2 ]
Set Field [ infoNumber, $infoNumber ]
Else
Set Field [ infoNumber, $infoNumber ]
Perform Find [ thingID = $thingID, infoNumber = -2 ]
Set Field [ infoNumber, $infoNumber -1 ]
End If
# Go back to layout you were in before
I would be interested to know if there was a better way!
You could do this by using relationships. Create a new table occurrence (say, History Previous) and link it to the list layout's table occurrence (say, History) with the following predicates:
History::ThingID = History Previous::ThingID
History::infoNumber > History Previous::infoNumber
Sort the relationship by History Previous::infoNumber, descending.
This will provide you with a set of related History records that appear earlier in the list for the relevant Thing. The first record will be the immediately previous one, thanks to the sorting.
Now, when you run the script, you can:
If [ Count ( History Previous::ThingID ) > 0 ]
Set Variable [ $infoNumber, History Previous::infoNumber ]
Set Field [ History Previous::infoNumber, History::infoNumber ]
Set Field [ History::infoNumber, $infoNumber ]
End If
Note that, although the History Previous relationship may refer to multiple records, you can rely on the relationship sorting to provide you with access to the first record, both when getting data from it (in the Set Variable step) and setting data into it (in the first Set Field step).

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