Koha/koha-tmpl/intranet-tmpl/prog/en/includes/av-build-dropbox.inc
Katrin Fischer 8218653df7
Bug 18680: Add an empty entry by default to sort1/sort2 values in patron account
When using sort1/sort2 with authorised values to create a pull down
list, there will be no empty entry unless one is manually added to
the authorised values list.

This is not a good default behaviour, as it can easily
cause errors on patron creation. Without the empty entry, the first
alphabetic value is pre-selected and will be saved if not explicitly
changed. It also doesn't allow to mark sort1/sort2 as mandatory,
as the value is always 'set', the required message won't be triggered.

This adds an empty parameter to av-build-dropbox.inc to allow selectively
adding this empty entry without causing side-effects in other places
this include is used.

To test:
- Create authorised values for either Bsort1 or Bsort2 authorised
  value category
- Create a new patron:
  - you should see a pull down list on one and an input field for the other
  - for the pull down list, there will be no empty entry and the first
    alphabetic value will be preselected
- Make your sort1 and sort2 mandatory using BorrowerMandatoryField
- Verify there is still on empty entry
- Apply patch
- Repeat tests and verify that the behaviour is as expected
  - There should now be an empty entry
  - When the field is marked mandatory and empty is left, the required
    warning will be shown.

Signed-off-by: David Roberts <david@koha-ptfs.co.uk>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-04-20 12:28:04 +01:00

28 lines
1.3 KiB
HTML

[% USE AuthorisedValues %]
[%# Parameters: %]
[%# name: the name of the select element %]
[%# category: the authorised value category %]
[%# default: the default authorised value to select %]
[%# class: the CSS class of the select element %]
[%# size: the size to use for the input (generated if the authorised value category does not exist). %]
[%# all: add a "All" entry. All and empty should not be used at the same time. %]
[%# empty: add an empty entry. All and empty should not be used at the same time. %]
[% SET avs = AuthorisedValues.GetAuthValueDropbox( category ) %]
[% DEFAULT class = '' size = 20 %]
[% IF avs %]
<select id="[% name | html %]" name="[% name | html %]" class="[% class | html %]" >
[% IF all %]<option value="">All</option>[% END %]
[% IF empty %]<option value=""></option>[% END %]
[% FOR av IN avs %]
[% IF av.authorised_value == default %]
<option value="[% av.authorised_value | html %]" selected="selected">[% av.lib | html_entity %]</option>
[% ELSE %]
<option value="[% av.authorised_value | html %]">[% av.lib | html_entity %]</option>
[% END %]
[% END %]
</select>
[% ELSE %]
<input type="text" id="[% name | html %]" name="[% name | html %]" size="[% size | html %]" value="[% default | html_entity %]" class="[% class | html %]" />
[% END %]