Page 1 of 1

Howto fh.getParam with childupdate

Posted: 10 Mar 2021 16:35
by JoopvB
I am trying to use fh.getParam to update list 2 depending on a selection in list 1. From the help on getParam I understand that this should be possible by using the childUpdate and child options.

But I must be doing something wrong because my childUpdate function doesn't get called.

A working example of list 1 steering the content of list 2 would be a great help.

Re: Howto fh.getParam with childupdate

Posted: 10 Mar 2021 17:01
by ColeValleyGirl
This is a place and address example, but should illustrate the general principles:

Code: Select all

{tag='BAPTISMPLACE', type="STRING" ,label= 'Baptism place', value='', child='BAPTISMADDRESS', childUpdate=function(place) return fh.createAddressList(place) end},
{tag='BAPTISMADDRESS', type="STRING", label= 'Baptism address', value=''}

Re: Howto fh.getParam with childupdate

Posted: 10 Mar 2021 17:36
by JoopvB
Thanks Helen,

I understand the example but can't seem to get it working with two lists. Question, where does the argument place come from?

Maybe it's not meant to be possible, but the idea is to have a list 1 (type = 'LIST') and based on a selection of the user in list 1 change te contents of list 2 (type = 'LIST'). The function I use is not in line (isn't necessary, is it?) because it's rather long.

Re: Howto fh.getParam with childupdate

Posted: 10 Mar 2021 17:46
by ColeValleyGirl
In the example 'place' is the value of the BAPTISMPLACE field -- I could have called it x but it would still be the value of the 'parent' field.

I don't have an example of one list updating the contents of another, but it should work -- you'd need to return a table of values that will also be the child field prompts (i.e. you can't have different prompts and values).

Re: Howto fh.getParam with childupdate

Posted: 10 Mar 2021 18:25
by JoopvB
I don't see it.

Got a lua error and it hangs:
... Files (x86)\Family Historian\Program\Lua\fhUtils.fh_lua:181: attempt to call a table value (field 'childUpdate')
stack traceback:
... Files (x86)\Family Historian\Program\Lua\fhUtils.fh_lua:181: in upvalue 'updateChild'
... Files (x86)\Family Historian\Program\Lua\fhUtils.fh_lua:507: in function <... Files (x86)\Family Historian\Program\Lua\fhUtils.fh_lua:497>
(...tail calls...)
[C]: in function 'iuplua.Popup'
... Files (x86)\Family Historian\Program\Lua\fhUtils.fh_lua:743: in function 'fhUtils.getParam'
[string "C:\Users\Joop\AppData\Local\Temp\~fhC889.tmp"]:76: in function 'main'
[string "C:\Users\Joop\AppData\Local\Temp\~fhC889.tmp"]:264: in main chunk

My statement is:

local fpar = fh.getParam('Field mapping', nil,
{{tag = 'tNotMappedText', label = 'Field to map to', type = 'LIST', value = tNotMappedText[1], values = tNotMappedText, childUpdate = doNewMatch(tCanMatch, value), child = 'tCanMatchText'},
{tag = 'tCanMatchText', label = 'Field to map to', type = 'LIST', value = tCanMatchText[1], values = tCanMatchText}},
{'OK, next', 'Auto-match', 'Reset', 'Cancel'})

What am I doing wrong?

Re: Howto fh.getParam with childupdate

Posted: 10 Mar 2021 18:28
by JoopvB
Forgot to include the update function.

function doNewMatch(tCanMatch, value)
--
-- Updates matching fields for new value in old fields list in getParam
if value then
tCanMatch = getMatch(tNewFields, value)
end
local tCanMatchText = getDisplayText(tCanMatch)
return tCanMatchText
end

Re: Howto fh.getParam with childupdate

Posted: 10 Mar 2021 20:40
by JoopvB
I think I have removed some inconsistencies, but still can't get it to work; it still ends with a lua error when I select a different item in list 1 (tNotMappedText). Every hint on this - for me new - use of Lua and fh.getParam is highly apricated.

The getParam statement is now:

local fpar = fh.getParam('Field mapping', nil, {{tag = 'tNotMappedText', label = 'Field to map', type = 'LIST',
value = tNotMappedText[1], values = tNotMappedText, childUpdate = doNewMatch(sOldField), child = 'tCanMatchText'},
{tag = 'tCanMatchText', label = 'Field to map to', type = 'LIST', value = tCanMatchText[1], values = tCanMatchText}},
{'OK, next', 'Auto-match', 'Reset', 'Cancel'})

The function doNewMatch is a local function as follows:

function doNewMatch(sOldField)
--
-- Updates matching fields for new value in old fields list in getParam
if sOldField then
tCanMatch = getMatchText(tCanMatch, tCanMatchText, sOldField)
end
return getDisplayText(tCanMatch)
end

Re: Howto fh.getParam with childupdate

Posted: 11 Mar 2021 08:46
by ColeValleyGirl
Joop, the childupdate function for the first list must return a table of values to populate the new list. (Looking at the code of fhUtils it looks like it will work with a table of values and a table of prompts.

Re: Howto fh.getParam with childupdate

Posted: 11 Mar 2021 10:50
by JoopvB
Helen, I'm completely lost. I made a very simple test script that is expected to do nothing more than depending on a name in the top list, change the entries in the bottom list. As soon as I change the top list I get the lua error and when I exit this, FH quits.

Either I don't understand the parameters of fh.getParam at all or what I'm trying is not meant to be possible with this utility. I've attached the test script in the hope that you (or anybody else reading this) can help me see the light in the (for me) dark fh.getParam forest. Thanks!!

N.B. Be aware that running this script and changing the top lists quits FH. So save what needs be saved before running.

Re: Howto fh.getParam with childupdate

Posted: 11 Mar 2021 11:37
by ColeValleyGirl
1. Try replacing the relevant lines with:

Code: Select all

	local fpar = fh.getParam('Allocate person to country', nil,
	  {{tag = 'persons', label = 'person', type = 'LIST', value = persons[1], values = persons,	childUpdate = change, child = 'countries'},
	 {tag = 'countries', label = 'country', type = 'LIST', value = countries[1], values = countries}},
	 {'OK', 'Cancel'})
	 
The changes are 'childUpdate = change, child = 'countries'

2. when you get a Lua error message press Continue not Exit to keep FH open (you may need to Continue through a number of errors).

Re: Howto fh.getParam with childupdate

Posted: 11 Mar 2021 13:01
by JoopvB
It works!

Thanks very much Helen!