[PATCH 1 of 5 seda] [js] Disable concept selector when no vocabulary is selected

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 17 10:45:09 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489733943 -3600
#      Fri Mar 17 07:59:03 2017 +0100
# Node ID 44a96295dbb6bbe1e1e9e79a53088823a8560322
# Parent  1f8ac02bbb5072c28de15149d30867731cc6d10c
[js] Disable concept selector when no vocabulary is selected

This makes the UX better by adding constraint on what is allowed or not.

diff --git a/cubicweb_seda/data/cubes.skoscomplete.js b/cubicweb_seda/data/cubes.skoscomplete.js
--- a/cubicweb_seda/data/cubes.skoscomplete.js
+++ b/cubicweb_seda/data/cubes.skoscomplete.js
@@ -18,15 +18,15 @@
 concept_autocomplete = {
     initConceptAutoCompleteWidget: function(masterSelectId, slaveSelectId, ajaxFuncName) {
         var masterSelect = cw.jqNode(masterSelectId);
         // bind vocabulary select to update concept autocompletion input on value change
         masterSelect.change(function() {
-            concept_autocomplete.updateCurrentSchemeEid(this);
+            concept_autocomplete.updateCurrentSchemeEid(this, slaveSelectId);
             concept_autocomplete.resetConceptFormField(slaveSelectId);
         });
         // initialize currentSchemeEid by looking the value of the master field
-        concept_autocomplete.updateCurrentSchemeEid(masterSelect);
+        concept_autocomplete.updateCurrentSchemeEid(masterSelect, slaveSelectId);
         // also bind the autocompletion widget
         cw.jqNode(slaveSelectId+'Label')
             .autocomplete({
                 source: function(request, response) {
                     if (concept_autocomplete.currentSchemeEid) {
@@ -72,14 +72,17 @@ concept_autocomplete = {
         });
         cw.jqNode(slaveSelectId+'Label').focusout(function(evt) {
             resetIfInvalidChoice();
         });
     },
-    updateCurrentSchemeEid: function(masterSelect) {
+    updateCurrentSchemeEid: function(masterSelect, slaveSelectId) {
         concept_autocomplete.currentSchemeEid = $(masterSelect).val();
         if (concept_autocomplete.currentSchemeEid == '__cubicweb_internal_field__') {
             concept_autocomplete.currentSchemeEid = null;
+            cw.jqNode(slaveSelectId+'Label').prop('disabled', true);
+        } else {
+            cw.jqNode(slaveSelectId+'Label').prop('disabled', false);
         }
     },
     resetConceptFormField: function(slaveSelectId) {
         cw.jqNode(slaveSelectId+'Label').val('');
         cw.jqNode(slaveSelectId).val('');


More information about the saem-devel mailing list