Browse Source

comboLookupEdit fix

SunRiseGC 2 years ago
parent
commit
4311d168e3
3 changed files with 13 additions and 15 deletions
  1. 9 3
      priv/js/comboLookup.js
  2. 3 2
      priv/js/sortable.js
  3. 1 10
      src/elements/combo/element_comboLookupEdit.erl

+ 9 - 3
priv/js/comboLookup.js

@@ -54,6 +54,8 @@ function comboSelect(uid, dom, row, feed, mod, id) {
     comboSelectVector(...arguments);
     comboSelectVector(...arguments);
   } else if (elem.parentNode.parentNode.getAttribute('data-group-input')) {
   } else if (elem.parentNode.parentNode.getAttribute('data-group-input')) {
     comboSelectGroup(...arguments);
     comboSelectGroup(...arguments);
+  } else if (elem.parentNode.parentNode.parentNode.getAttribute('data-edit-input') && elem.parentNode.parentNode.parentNode.getAttribute('multiple') === "true") {
+    comboSelectVector(...arguments); comboCloseFormById(`${dom}_form`);
   } else {
   } else {
     comboSelectDefault(...arguments);
     comboSelectDefault(...arguments);
   }
   }
@@ -138,8 +140,8 @@ function comboSelectVector(uid, dom, row, feed, mod, id) {
       }
       }
     }
     }
   }
   }
-}
 
 
+}
 
 
 function comboSelectGroup(uid, dom, row, feed, mod, id) {
 function comboSelectGroup(uid, dom, row, feed, mod, id) {
   const selected = qi(id);
   const selected = qi(id);
@@ -188,7 +190,6 @@ function comboLookupKeydown(uid, dom, feed, mod) {
     if (event.key == 'Meta')  { return }
     if (event.key == 'Meta')  { return }
     if (event.key == 'Alt')   { return }
     if (event.key == 'Alt')   { return }
     if (event.key == 'Shift') { return }
     if (event.key == 'Shift') { return }
-    if (event.key == 'Enter') { return }
     var dropdown = qi(dom).closest('.dropdown');
     var dropdown = qi(dom).closest('.dropdown');
     var char = event.which || event.keyCode;
     var char = event.which || event.keyCode;
     if (qi(dom).value == '' && event.key == 'Backspace') { return }
     if (qi(dom).value == '' && event.key == 'Backspace') { return }
@@ -226,7 +227,6 @@ function comboLookupKeyup(uid, dom, feed, mod) {
     if (event.key == 'Meta')  { return }
     if (event.key == 'Meta')  { return }
     if (event.key == 'Alt')   { return }
     if (event.key == 'Alt')   { return }
     if (event.key == 'Shift') { return }
     if (event.key == 'Shift') { return }
-    if (event.key == 'Enter') { return }
     if (event.key == 'Tab') { dropdown.classList.remove('dropdown-open'); return }
     if (event.key == 'Tab') { dropdown.classList.remove('dropdown-open'); return }
     var char = event.which || event.keyCode;
     var char = event.which || event.keyCode;
     if (char == 27 || (char == 8 || char == 46) && qi(dom).value == '') { 
     if (char == 27 || (char == 8 || char == 46) && qi(dom).value == '') { 
@@ -279,6 +279,12 @@ function clearInput(dom) {
   }
   }
   comboLookupChange(dom);
   comboLookupChange(dom);
   comboClear(dom);
   comboClear(dom);
+
+  if (input && input.getAttribute('data-update')) {
+    let update = dec(unbase64(input.getAttribute('data-update')));
+    update.v[5] = atom('skip');
+    direct(update);
+  }
 }
 }
 
 
 function comboLookupModifyValues(listId) {
 function comboLookupModifyValues(listId) {

+ 3 - 2
priv/js/sortable.js

@@ -229,7 +229,8 @@ function getSortableValues(list) {
 
 
 function appendItemFromBind(dom,value,bind) {
 function appendItemFromBind(dom,value,bind) {
   var sortable = SortableMap.get('#'+dom);
   var sortable = SortableMap.get('#'+dom);
-  var isAdded = sortable.items.map(el => el.textContent).includes(value || {"text": value, "bind": bind});
+  var isAdded = sortable.items.map(el => el.textContent).includes(value || {"text": value, "bind": bind}) ||
+                sortable.items.map(el => el.getAttribute("data-bind")).includes(bind);
   if(!isAdded) {
   if(!isAdded) {
     var template = document.createElement('template');
     var template = document.createElement('template');
     template.innerHTML =
     template.innerHTML =
@@ -246,4 +247,4 @@ function appendItemFromBind(dom,value,bind) {
     sortable.list.appendChild(new_item);
     sortable.list.appendChild(new_item);
     sortable.items.push(new_item);
     sortable.items.push(new_item);
   }
   }
-}
+}

+ 1 - 10
src/elements/combo/element_comboLookupEdit.erl

@@ -13,21 +13,12 @@ render_element(#comboLookupEdit{id=Id, input=Input, disabled=Disabled, validatio
     #panel{
     #panel{
       id = Id,
       id = Id,
       validation = Validation,
       validation = Validation,
-      data_fields = [{<<"data-edit-input">>,<<"data-edit-input">>}],
+      data_fields = [{<<"data-edit-input">>,<<"data-edit-input">>}, {<<"multiple">>,Multiple}],
       body = [
       body = [
         #panel{
         #panel{
           style = "display: flex; position: relative; width: 100%; justify-content: center;",
           style = "display: flex; position: relative; width: 100%; justify-content: center;",
           body =
           body =
             [ Input,
             [ Input,
-              case Multiple of
-                true ->
-                  #link{
-                    class = [button, sgreen, 'add-btn'],
-                    style = "min-width: 40px; text-align: center; height: fit-content; margin-left: 5px;",
-                    onclick = nitro:jse("addSortableItemFrom('#" ++ ListId ++ "', '" ++ InputId ++ "')"),
-                    body = <<"+">>};
-                false -> []
-              end,
               case Disabled of
               case Disabled of
                 true -> [];
                 true -> [];
                 _ ->
                 _ ->