1

Topic: Changing the way species name are displayed in data entry

On the standard 'Enter a list of species' data entry for, once a species name is selected it displays common name, scientific name, taxonomic group and identification difficulty. I was looking to see if I change the behaviour of the 'Enter a casual record' form to mimic this and thus help limit the number of Magpie/Painted-lady/Redshank errors being generated.

I started poking around the code to see if I could work out and frankly got quite lost quite quickly, so thought it might be something that someone could point me in the right direction of? Is it in the code or can it actually be done in the form design?

Dave

Dave Slade
Senior IT & Records Officer,
15 Talbot Road, Talbot Green, Pontyclun, CF72 8AD
www.sewbrec.org.uk, www.sewbrecord.org.uk

2

Re: Changing the way species name are displayed in data entry

Hi Dave,

I, too, will have to poke around the code. I start with the knowledge that the control on the casual record form will be data_entry_helper::species_autocomplete().

I observe there is a template called 'autocomplete_javascript' for the javascript that drives the control. The declaration of the global array of $indicia_templates can be found at the start of helper_base.php.

This script (which can be more easily understood by inspecting the actual javascript in the browser) makes use of a jQuery autocomplete plugin which can be found in iform/media/js/jquery.autocomplete.js

By stepping through that code I see that, when a species is selected, the text box is populated with a the contents of a 'result' property.

Working back out again, that result property is populated by the autocomplete_javascript template with 'item.{captionField}'. 'item' is an object returned by the database query containing many fields including common name, scientific name, etc. {captionField} is a token which is replaced by the name of just one field.

The way to deal with this, then, is to either override the autocomplete_javascript template, as described at http://indicia-docs.readthedocs.io/en/l … lity.html, or improve the client_helpers code.

Overriding the template is problematic because the fields in item depend upon whether we are querying the cache tables or not. However, since all production sites should be using the cache you could do a job that would work well enough. The override could just be a concatenation of fields, making use of the following,
- item.original: the taxon that was entered
- item.language_iso: the language of the entered taxon (e.g. lat for latin, eng for english..)
- item.authority: the authority of the entered taxon
- item.preferred_taxon: the latin name of the taxon
- item.'preferred_authority: the authority of the preferred taxon name
- item.default_common_name: the common name of the taxon
- item.taxon_group: the taxon group

However, a better result will be obtained by something more dynamic like data_entry_helper::build_species_autocomplete_item_function() which takes in to account the language of the name entered by the recorder.

It's not the simplest of configuration. If you would prefer a better fix, you could add a feature request for this to the client_helpers issue queue on Github but there is no telling if/when it would be acted on.

Hope that helps,
Jim Bacon.

3

Re: Changing the way species name are displayed in data entry

This is more complicated than I was imagining. In my mind, the build_species_autocomplete_item_function() is doing exactly what I want it to do on the 'Enter a list' form, but then doing something (in my opinion) less useful on the 'Enter a Casual' Record form. What I don't get is at what point the behaviour is changing - both are built from the same form (dynamic_sample_occurrence.php).

From what I can see in dynamic_sample_occurrence.php the version I want is in the get_form_html() as the 'Else' option, which implies that the Casual Record form is over-riding the 'build_grid_autocomplete_function'. Although that reads as though it is for a pre-built grid (i.e. where a list of species is already populated, for a user to select). Is this the case or I am in the wrong section?

Dave Slade
Senior IT & Records Officer,
15 Talbot Road, Talbot Green, Pontyclun, CF72 8AD
www.sewbrec.org.uk, www.sewbrecord.org.uk

4

Re: Changing the way species name are displayed in data entry

Hi

I think what you are looking at is the code that creates the pop-up list of suggestions. Both forms use data_entry_helper::build_species_autocomplete_item_function() without any override and show scientific name, common name and taxon group.

Where the two forms diverge is at the end of get_control_species(). If you are in gridmode the outcome is that data_entry_helper::species_checklist() is used to build the species input otherwise (assuming autocomplete is selected as the means of input) data_entry_helper::species_autocomplete() is used.

I described above how species_autocomplete() determines what to put in the species text box. In contrast, species_checklist() has an option, PHPtaxonLabel which, if true, evaluates the taxon_label template as PHP. This is exploited in dynamic_sample_occurrence::build_grid_taxon_label_function() to get the output you prefer.

Adding a similar PHPtaxonLabel option to the species_autocomplete() might be (for consistency as much as anything) the way I would consider building the functionality you like in to the client_helpers.

Jim Bacon.

5 (edited by DaveSlade 20-12-2016 10:43:39)

Re: Changing the way species name are displayed in data entry

Ok, that makes sense! I'll let you know how I get on.
Many thanks again Jim!
Dave

Dave Slade
Senior IT & Records Officer,
15 Talbot Road, Talbot Green, Pontyclun, CF72 8AD
www.sewbrec.org.uk, www.sewbrecord.org.uk

6

Re: Changing the way species name are displayed in data entry

If you are taking the template route then that will be local to your site. If you are looking at modifying the client_helpers then that would be something we could pull in to the repository and share if it is backwards compatible.

Jim.

7

Re: Changing the way species name are displayed in data entry

Just to let you know, I have parked this development for the time being due to other work pressures. I will let you know if I get around to picking it up again!
Dave

Dave Slade
Senior IT & Records Officer,
15 Talbot Road, Talbot Green, Pontyclun, CF72 8AD
www.sewbrec.org.uk, www.sewbrecord.org.uk