* Howto fh.getParam with childupdate

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Howto fh.getParam with childupdate

Post by JoopvB » 10 Mar 2021 16:35

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.

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Howto fh.getParam with childupdate

Post by ColeValleyGirl » 10 Mar 2021 17:01

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=''}

avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Howto fh.getParam with childupdate

Post by JoopvB » 10 Mar 2021 17:36

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.

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Howto fh.getParam with childupdate

Post by ColeValleyGirl » 10 Mar 2021 17:46

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).

avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Howto fh.getParam with childupdate

Post by JoopvB » 10 Mar 2021 18:25

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?

avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Howto fh.getParam with childupdate

Post by JoopvB » 10 Mar 2021 18:28

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

avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Howto fh.getParam with childupdate

Post by JoopvB » 10 Mar 2021 20:40

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

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Howto fh.getParam with childupdate

Post by ColeValleyGirl » 11 Mar 2021 08:46

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.

avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Howto fh.getParam with childupdate

Post by JoopvB » 11 Mar 2021 10:50

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.
Attachments
Test getParam.fh_lua
(934 Bytes) Downloaded 94 times

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Howto fh.getParam with childupdate

Post by ColeValleyGirl » 11 Mar 2021 11:37

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).

avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Howto fh.getParam with childupdate

Post by JoopvB » 11 Mar 2021 13:01

It works!

Thanks very much Helen!

Post Reply