Alphabetize fields with multiple inputs


#1

Is there a way to alphabetize metadata fields that have multiple inputs, such as Subjects, in the public-facing item pages? I haven’t seen a plugin that does this but please tell me if I’ve overlooked something. If there’s no plugin, would this be possible to code into show.php? Thanks!


#2

@alexlow or anyone else - did you ever find a solution for this? I’m interested in doing something similar, except I’d like to also alphabetize entries on the back end, too. When several subjects are entered and the record is saved, the subjects are automatically sorted and displayed.


#3

No solution yet. I’m hoping someone on the forum can offer advice.


#4

You want to alphabetize the values, rather than have them appear in the order they appear on the input form? Obviously there’s a manual approach of just inputting the values in alphabetical order.

Automatically re-ordering the elements for display can also be done, by modifying the view file common/record-metadata.php. You can copy this file from application/views/scripts/common/record-metadata.php and put it in your theme at common/record-metadata.php

Then, in the copy of the file you just put into your theme, add the line

<?php sort($elementInfo['texts']); ?>

right above this line that’s already in the file:

<?php foreach ($elementInfo['texts'] as $text): ?>

#5

Thank you, @jflatnes! Everything’s almost working perfectly. All the values are alphabetizing correctly except for records with the Oral History item type. For some reason the first alphabetical value for every field is appended to the end. For example:

Fort Snelling (Minn.)
Minnesota
Texas
Wisconsin
Corpus Christi (Tex.)

This is happening on every field in the Oral History records, both Dublin Core and Item Type Metadata. Thoughts?

Edit: Okay, this is happening on other records as well, not just Oral Histories. Sometimes the sort function will ignore what the first value is when sorting and append that value to the end. I’m not seeing a pattern of when this happens and when it doesn’t.


#6

Could those values have something different at the front, a leading space for example?


#7

I’m a dunce. Leading spaces were the culprit. Thank you very much for your help!