Browse code

[calendar] BM-14833 Fix: Prevent to create empty tag from event form

Mehdi Rande authored on 27/06/2019 11:51:39
Showing 1 changed files
... ...
@@ -25,6 +25,7 @@ goog.require("goog.ui.ComboBox");
25 25
 goog.require("goog.ui.ComboBoxItem");
26 26
 goog.require("net.bluemind.ui.form.TagFieldTemplate");
27 27
 goog.require("goog.math");
28
+goog.require('goog.string');
28 29
 goog.provide("net.bluemind.ui.form.TagField.ComboBoxItemRenderer");
29 30
 goog.provide("net.bluemind.ui.form.TagField.ComboBoxItem");
30 31
 /**
... ...
@@ -82,8 +83,17 @@ net.bluemind.ui.form.TagField.prototype.createField = function() {
82 83
 
83 84
   /** @meaning tags.selectOne */
84 85
   var MSG_TAG_SELECT = goog.getMsg('Select a tag...');
86
+
85 87
   cb.setId('tagsbox');
86 88
   cb.setDefaultText(MSG_TAG_SELECT);
89
+  cb.setMatchFunction(function(str1, str2) {
90
+    /** @meaning tags.create */
91
+    var MSG_TAG_CREATE = goog.getMsg('Create tag');
92
+    if (goog.string.startsWith(str1, MSG_TAG_CREATE.toLowerCase())) {
93
+      return str2.length > 0;
94
+    }
95
+    return goog.string.startsWith(str1, str2);
96
+  })
87 97
   this.addChild(cb);
88 98
   cb.render(this.getElementByClass(goog.getCssName('field-base-field')));
89 99
   cb.setEnabled(this.isEnabled());
... ...
@@ -104,16 +114,12 @@ net.bluemind.ui.form.TagField.prototype.enterDocument = function() {
104 114
   });
105 115
   
106 116
   this.getHandler().listen(this.getChild('tagsbox'), 'change', function(evt) {
107
-    var item = this.getChild('tagsbox').getItemAt(this.getChild('tagsbox').getItemCount() - 1);
108
-    if (evt.target.getToken().length > 0) {
109
-      item.setVisible(true);
110
-      /** @meaning tags.create */
111
-      var MSG_TAG_CREATE = goog.getMsg('Create tag');
112
-      item.setContent(MSG_TAG_CREATE + ' "' + evt.target.getValue() + '" ...');
113
-      item.setValue('create');
114
-    } else {
115
-      item.setVisible(false);
116
-    }
117
+    var tagsbox = this.getChild('tagsbox');
118
+    var item = tagsbox.getItemAt(tagsbox.getItemCount() - 1);
119
+    /** @meaning tags.create */
120
+    var MSG_TAG_CREATE = goog.getMsg('Create tag');
121
+    item.setContent(MSG_TAG_CREATE + ' "' + evt.target.getValue() + '" ...');
122
+    tagsbox.lastToken_ = tagsbox.lastToken ? tagsbox.lastToken : null;
117 123
   });
118 124
   this.getHandler().listen(this.getChild('bullets').getKeyEventTarget(), goog.events.EventType.FOCUS, function(evt) {
119 125
     this.getChild('tagsbox').getLabelInput().focusAndSelect();
... ...
@@ -195,13 +201,9 @@ net.bluemind.ui.form.TagField.prototype.refresh_ = function() {
195 201
 
196 202
   /** @meaning tags.create */
197 203
   var MSG_TAG_CREATE = goog.getMsg('Create tag');
198
-  var createTag = new goog.ui.ComboBoxItem(MSG_TAG_CREATE, 'create');
199
-  createTag.setId('create-tag');
200
-  createTag.setContent(MSG_TAG_CREATE + ' "' + this.getChild('tagsbox').getValue()
201
-      + '" ...');
202
-  createTag.setSticky(true);
203
-  createTag.setVisible(this.getChild('tagsbox').getValue() != '');
204
-  this.getChild('tagsbox').addItem(createTag);
204
+  var item = new goog.ui.ComboBoxItem(MSG_TAG_CREATE, 'create');
205
+  item.setId('create-tag');
206
+  this.getChild('tagsbox').addItem(item);
205 207
 
206 208
   this.resizeInput_();
207 209
 }