12479: Allow the user to edit the currently accepted value on a
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Fri, 5 Jan 2018 19:34:35 +0000 (16:34 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Fri, 5 Jan 2018 19:34:35 +0000 (16:34 -0300)
selectize field.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

apps/workbench/app/assets/javascripts/components/edit_tags.js

index e4eb2007bba646d84fce0b4804c0bcc77b389db9..fa3f13e4ac7ca000d5db54710065937e6adcffe2 100644 (file)
@@ -27,6 +27,16 @@ window.SimpleInput = {
 }
 
 window.SelectOrAutocomplete = {
+    onFocus: function(vnode) {
+        // Allow the user to edit an already entered value by removing it
+        // and filling the input field with the same text
+        activeSelect = vnode.state.selectized[0].selectize
+        value = activeSelect.getValue()
+        if (value.length > 0) {
+            activeSelect.clear(silent = true)
+            activeSelect.setTextboxValue(value)
+        }
+    },
     view: function(vnode) {
         return m("input", {
             style: {
@@ -37,7 +47,7 @@ window.SelectOrAutocomplete = {
         }, vnode.attrs.value)
     },
     oncreate: function(vnode) {
-        this.selectized = $(vnode.dom).selectize({
+        vnode.state.selectized = $(vnode.dom).selectize({
             labelField: 'value',
             valueField: 'value',
             searchField: 'value',
@@ -59,10 +69,13 @@ window.SelectOrAutocomplete = {
                 if (val != '') {
                     vnode.attrs.value(val)
                 }
+            },
+            onFocus: function() {
+                vnode.state.onFocus(vnode)
             }
         })
         if (vnode.attrs.setFocus) {
-            this.selectized[0].selectize.focus()
+            vnode.state.selectized[0].selectize.focus()
         }
     }
 }