Merge branch 'MDL-63125-37' of https://github.com/paulholden/moodle into MOODLE_37_STABLE

This commit is contained in:
Adrian Greeve
2019-10-23 11:07:10 +08:00
7 changed files with 48 additions and 19 deletions
File diff suppressed because one or more lines are too long
+15 -14
View File
@@ -107,11 +107,12 @@ function($, log, str, templates, notification, LoadingIcon) {
} else {
label = $(ele).html();
}
items.push({label: label, value: $(ele).attr('value')});
if (label !== '') {
items.push({label: label, value: $(ele).attr('value')});
}
}
});
var context = $.extend({items: items}, options, state);
// Render the template.
return templates.render('core/form_autocomplete_selection', context)
.then(function(html, js) {
@@ -161,19 +162,16 @@ function($, log, str, templates, notification, LoadingIcon) {
var deselectItem = function(options, state, item, originalSelect) {
var selectedItemValue = $(item).attr('data-value');
// We can only deselect items if this is a multi-select field.
if (options.multiple) {
// Look for a match, and toggle the selected property if there is a match.
originalSelect.children('option').each(function(index, ele) {
if ($(ele).attr('value') == selectedItemValue) {
$(ele).prop('selected', false);
// We remove newly created custom tags from the suggestions list when they are deselected.
if ($(ele).attr('data-iscustom')) {
$(ele).remove();
}
// Look for a match, and toggle the selected property if there is a match.
originalSelect.children('option').each(function(index, ele) {
if ($(ele).attr('value') == selectedItemValue) {
$(ele).prop('selected', false);
// We remove newly created custom tags from the suggestions list when they are deselected.
if ($(ele).attr('data-iscustom')) {
$(ele).remove();
}
});
}
}
});
// Rerender the selection list.
return updateSelectionList(options, state, originalSelect)
.then(function() {
@@ -571,6 +569,9 @@ function($, log, str, templates, notification, LoadingIcon) {
var existingValues = [];
// Now destroy all options that are not currently selected.
if (!options.multiple) {
originalSelect.children('option').remove();
}
originalSelect.children('option').each(function(optionIndex, option) {
option = $(option);
if (!option.prop('selected')) {
+28
View File
@@ -0,0 +1,28 @@
@core @javascript @core_form
Feature: Autocomplete functionality in forms
For forms including autocomplete elements
As a user
I need to use the autocomplete form element
Background:
Given the following "users" exist:
| username | firstname | lastname |
| user1 | Jane | Jones |
| user2 | Sam | Smith |
And I log in as "admin"
Scenario: Use autocomplete element which accepts a single value
When I navigate to "Users > Privacy and policies > Data requests" in site administration
And I follow "New request"
And I open the autocomplete suggestions list
And I click on "Jane Jones" item in the autocomplete list
Then "Jane Jones" "autocomplete_selection" should exist
# Change selection
And I open the autocomplete suggestions list
And I click on "Sam Smith" item in the autocomplete list
And "Sam Smith" "autocomplete_selection" should exist
And "Jane Jones" "autocomplete_selection" should not exist
# Remove selection
And I click on "Sam Smith" "autocomplete_selection"
And "Sam Smith" "autocomplete_selection" should not exist
And I should see "No selection" in the ".form-autocomplete-selection" "css_element"
@@ -41,7 +41,7 @@
<span class="accesshide">{{#str}}selecteditems, form{{/str}}</span>
{{#items}}
<span role="listitem" data-value="{{value}}" aria-selected="true" class="badge badge-info mb-3 mr-1" style="font-size: 100%">
{{#multiple}}<span aria-hidden="true">× </span>{{/multiple}}{{{label}}}
<span aria-hidden="true">× </span>{{{label}}}
</span>
{{/items}}
{{^items}}
+1 -1
View File
@@ -285,7 +285,7 @@ fieldset.coursesearchbox label {
min-height: 2 * $input-padding-y-sm + 2 * $font-size-base;
}
.form-autocomplete-multiple [role=listitem] {
.form-autocomplete-selection [role=listitem] {
cursor: pointer;
white-space: inherit;
word-break: break-word;
+1 -1
View File
@@ -14832,7 +14832,7 @@ fieldset.coursesearchbox label {
margin: 0.25rem;
min-height: 2.375rem; }
.form-autocomplete-multiple [role=listitem] {
.form-autocomplete-selection [role=listitem] {
cursor: pointer;
white-space: inherit;
word-break: break-word;
+1 -1
View File
@@ -15089,7 +15089,7 @@ fieldset.coursesearchbox label {
margin: 0.25rem;
min-height: 2.375rem; }
.form-autocomplete-multiple [role=listitem] {
.form-autocomplete-selection [role=listitem] {
cursor: pointer;
white-space: inherit;
word-break: break-word;