MDL-59368 inplace_editable: Focus on auto-complete
authorDamyon Wiese <damyon@moodle.com>
Fri, 30 Jun 2017 06:15:24 +0000 (14:15 +0800)
committerDamyon Wiese <damyon@moodle.com>
Wed, 12 Jul 2017 02:07:58 +0000 (10:07 +0800)
Also fix JS coding style and build the amd.

lib/amd/build/form-autocomplete.min.js
lib/amd/build/inplace_editable.min.js
lib/amd/src/form-autocomplete.js
lib/amd/src/inplace_editable.js

index 17220a3..7e9a903 100644 (file)
Binary files a/lib/amd/build/form-autocomplete.min.js and b/lib/amd/build/form-autocomplete.min.js differ
index 372f328..f77bf3d 100644 (file)
Binary files a/lib/amd/build/inplace_editable.min.js and b/lib/amd/build/inplace_editable.min.js differ
index 361d0e1..f199838 100644 (file)
@@ -703,6 +703,7 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
          * @param {Boolean} caseSensitive - If search has to be made case sensitive.
          * @param {Boolean} showSuggestions - If suggestions should be shown
          * @param {String} noSelectionString - Text to display when there is no selection
+         * @return {Promise}
          */
         enhance: function(selector, tags, ajax, placeholder, caseSensitive, showSuggestions, noSelectionString) {
             // Set some default values.
@@ -769,7 +770,7 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
             var renderDatalist = templates.render('core/form_autocomplete_suggestions', context);
             var renderSelection = templates.render('core/form_autocomplete_selection', context);
 
-            $.when(renderInput, renderDatalist, renderSelection).done(function(input, suggestions, selection) {
+            return $.when(renderInput, renderDatalist, renderSelection).done(function(input, suggestions, selection) {
                 // Add our new UI elements to the page.
                 originalSelect.after(suggestions);
                 originalSelect.after(input);
@@ -808,6 +809,7 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
                 }
                 // Show the current values in the selection list.
                 updateSelectionList(options, state, originalSelect);
+                return true;
             });
         }
     };
index 9734c2a..471795c 100644 (file)
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  * @since      3.1
  */
-define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str', 'core/config', 'core/url', 'core/form-autocomplete'],
+define(['jquery',
+        'core/ajax',
+        'core/templates',
+        'core/notification',
+        'core/str',
+        'core/config',
+        'core/url',
+        'core/form-autocomplete'],
         function($, ajax, templates, notification, str, cfg, url, autocomplete) {
 
     $('body').on('click keypress', '[data-inplaceeditable] [data-inplaceeditablelink]', function(e) {
@@ -226,17 +233,17 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
             str.get_string('savechanges', 'core').then(function(s) {
                 return templates.renderPix('e/save', 'core', s);
             }).then(function(html) {
-                saveelement.append(html); 
+                saveelement.append(html);
                 return;
             }).fail(notification.exception);
 
             str.get_string('cancel', 'core').then(function(s) {
                 return templates.renderPix('e/cancel', 'core', s);
             }).then(function(html) {
-                cancelelement.append(html); 
+                cancelelement.append(html);
                 return;
             }).fail(notification.exception);
-            
+
             el.html('')
                 .append(lbl)
                 .append(inputelement)
@@ -251,7 +258,11 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
                                  attributes.placeholder,
                                  attributes.caseSensitive,
                                  attributes.showSuggestions,
-                                 attributes.noSelectionString);
+                                 attributes.noSelectionString)
+                .then(function() {
+                // Focus on the enhanced combobox.
+                el.find('[role=combobox]').focus();
+            });
 
             inputelement.on('keyup', function(e) {
                 if ((e.type === 'keyup' && e.keyCode === 27) || e.type === 'focusout') {