1

Topic: Custom attributes

Hi,

I'm trying to find documentation that will tell me how to set up custom attributes where when one option is chosen then another option appears e.g. a text box or another lookup list. Basically the functionality that is seen on the iRecord casual record submission form for the Habitat section.

Cheers,
Fiona

Fiona McCrory
CEDaR Website Officer
www.nmni.com/cedar

2

Re: Custom attributes

Hi Fiona
First, you need a custom attribute that points to a termlist with some hierarchical structure in it. You can either use the Child Terms tab to do this, or import the termlist from CSV using a parent column to link child terms to their parents. Then, create the custom attribute. On the setup attributes link for the survey on the warehouse, edit the attribute and set "Default control type" to hierarchical_select.
Cheers
John

John van Breda
Biodiverse IT

3

Re: Custom attributes

Hi John,

Thanks for that explanation - I seem to have that working successfully. Can I extend the question to how it's done if you want a text box rather than a term to appear i.e. the person chooses 'Other' and then has to type the explanation in to a text input?

Cheers,
Fiona

Fiona McCrory
CEDaR Website Officer
www.nmni.com/cedar

4

Re: Custom attributes

Hi Fiona,

I've never used this facility but I have noticed it lurking in the code. A quick search finds the option is described for controls of type checkbox_group but it may well work for radio groups too. No hint of it for selects. I've written my own javascript when I have needed to do this.

The options are as follows
otherItemId
Optional. The termlists_terms id of the checkbox_group item that will be considered as "Other".
When this checkbox is selected then another textbox is displayed allowing specific details relating to the
Other item to be entered. The otherValueAttrId and otherTextboxLabel options must be specified to use this feature.
otherValueAttrId
Optional. The attribute id where the "Other" text will be stored, e.g. smpAttr:10. See otherItemId option description.
otherTextboxLabel
Optional. The label for the "Other" textbox. See otherItemId, otherValueAttrId option descriptions.

So you would to create the attribute for the other text in the warehouse and choose checkbox group as the default input for the princial attribute. Then, in the form structure of your Drupal page, you would have to supply values for these options to the principal attribute using the @option = value format.

Jim Bacon

5

Re: Custom attributes

Thanks Jim, I'll have a go at your suggestion and see how I get on.
Fiona

Fiona McCrory
CEDaR Website Officer
www.nmni.com/cedar

6

Re: Custom attributes

Hi,

Is is possible to use a termlist/lookup list in a different kind for several surveys or forms? I'm using a lookup list with 10 values, 3 of them have child values. Hierachical select works fine for selecting child values.
But child values should not appear in all forms, just in one.

Cheers
juergen

7

Re: Custom attributes

Hi Juergen,

One term list may be used by many custom attributes.
One custom attribute may be used by many surveys.
Each custom attribute may be configured independently for each survey.
Each form shows the custom attributes, according to their configuration, for one survey.

Therefore, I think the answer to your question is yes. You can use the same term list and the same custom attribute and show it as check boxes in one survey form and a select on another survey form.

However, I am not entirely sure what you will see if you have a hierarchical term list and then choose not to use a hierarchical_ select control. I think you get just the top level terms.

Give it a try and let us know.

Jim Bacon.

8

Re: Custom attributes

Hi Jim,

I already tried it. But if I have child values in my termlist, I always get all values, in hierarchical select control or just in select control.
The difference is in hierarchical select you select first the top level value, then you get the options to choose the child value.
In select control you get all values directly.
Maybe I should us different termlists for the same sustom attribute in different surveys?

Juergen

9

Re: Custom attributes

Well, that was the other likely possibility!

Before I go further, my recommendation is that your data model should represent the data you are collecting as clearly as possible. I have a plan to enable you to use one termlist. However, choose that option if it is a good data model, not just to save a bit of effort setting up attributes ;-)

I have created a hierarchical termlist and here is a snippet from the termlists_terms table of the database.

--------------------------------------------
| id   | termlist_id | term_id | parent_id |
|------|-------------|---------|-----------|
| 4827 | 362         | 4876    |           |
| 4828 | 362         | 4877    |           |
| 4829 | 362         | 4878    |           |
| 4830 | 362         | 4879    |           |
| 4831 | 362         | 4880    | 4827      |
| 4834 | 362         | 4883    | 4828      |
| 4835 | 362         | 4884    | 4828      |
| 4836 | 362         | 4885    | 4827      |
| 4837 | 362         | 4886    | 4827      |
--------------------------------------------

It is one termlist (termlist_id = 362)
It has 9 terms (each with a term_id)
Each has an id in the termlist_terms table which can appear in the parent_id column.
4827 is the parent of 3 children and 4828 is the parent of 2 children.

I conclude that the select chooses all terms with termlist_id = 362.
If we can add an extra filter, where parent_id is null, then it will only select the top level items.

I can add options to controls on the form in the Form Structure of the User Interface section (assuming you are using Drupal and the Sample with Occurrences form or similar). I happen to know that I can include additional database filters in the extraParams option. After a bit of digging I found a null value is a special case which is passed as a sting of 'NULL'

Thus, for my custom attribute (which happens to be a sample attribute with id of 571) I can insert my custom attribute and pass it an option as follows:

[smpAttr:571]
@extraParams={"parent_id":"NULL"}

This limits the select to just the top level items as desired.

Congratulations if you understood all that!

Jim Bacon.

10

Re: Custom attributes

Hi Jim,

great, this works.
Thanks a lot.

Juergen