]> git.agnieray.net Git - galette.git/commitdiff
Fix social networks search dropdown
authorGuillaume AGNIERAY <dev@agnieray.net>
Sat, 20 Jan 2024 14:38:38 +0000 (15:38 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Tue, 23 Jan 2024 07:28:28 +0000 (08:28 +0100)
fixes #1760

Clear dropdown and text values after clone
Add new social network directly on input

galette/templates/default/elements/edit_socials.html.twig
galette/templates/default/elements/js/choose_social.js.twig [new file with mode: 0644]
galette/templates/default/pages/member_form.html.twig
galette/templates/default/pages/preferences.html.twig
ui/semantic/galette/modules/dropdown.overrides

index 84c7f14cabc080219eaa71fce98c9560a1e2a37c..7b795dffbd07f8e9534c7d536fb7c0411712d41a 100644 (file)
                 <label>{{ _T("Add new social network") }}</label>
                 <div class="combo-social fields">
                     <div class="field">
-                        <select name="social_new_type_1" id="social_new_type_1" class="socials_dropdown ui search dropdown">
-                            <option value="">{{ _T("Choose or enter your own...") }}</option>
+                        <div id="social_new_type_1" class="jsonly search-dropdown socials-dropdown ui input">
+                            <input id="social_new_type_input_1" type="hidden" name="social_new_type_1" value="">
+                            <i class="jsonly displaynone dropdown icon" aria-hidden="true"></i>
+                            <div class="jsonly displaynone default text">{{ _T("Choose or enter your own...") }}</div>
+                            <div class="jsonly displaynone menu">
                             {% for social_type in osocials.getSystemTypes(false) %}
-                                <option value="{{ social_type }}">{{ osocials.getSystemType(social_type) }}</option>
+                                <div class="item" data-value="{{ social_type }}">{{ osocials.getSystemType(social_type) }}</div>
                             {% endfor %}
-                        </select>
+                            </div>
+                        </div>
                     </div>
                     <div class="field">
-                        <input type="text" name="social_new_value_1" id="social_new_value_1" value="" size="50"/>
+                        <input type="text" name="social_new_value_1" id="social_new_value_1" value="" size="50" class="value"/>
                     </div>
                 </div>
                 <a href="#" class="ui tiny green labeled icon button action addsocial">
                     {{ _T("Add") }}
                 </a>
             </div>
-            <script type="text/javascript">
-                var _dropdown = function(selector) {
-                    if ( !selector ) {
-                        selector = '.socials_dropdown';
-                    }
-
-                    $(selector).dropdown({
-                        allowAdditions: true
-                    });
-                }
-
-                var _rmFilter = function(elt) {
-                    if ( typeof elt == 'undefined') {
-                        elt = $('#social .stored');
-                    }
-                    elt.find('.delsocial').click(function(e){
-                        e.preventDefault();
-                        var _this = $(this);
-                        _this.parents('.field.stored').remove();
-                    });
-                }
-
-                $(function(){
-                    _rmFilter();
-                    _dropdown();
-
-                    $('a.addsocial').click(function(e) {
-                        e.preventDefault();
-
-                        var _newindex = $(this).parents('.addsocial').find('.combo-social:last select').attr('id').replace('social_new_type_', '');
-                        ++_newindex;
-                        $(this).parents('.addsocial').find ('.combo-social:last')
-                            .clone() // copy
-                            .insertAfter('#social .combo-social:last') // where
-                            .find('select').attr('id', 'social_new_type_' + _newindex).attr('name', 'social_new_type_' + _newindex)
-                            .parent().parent().parent().find('input').attr('id', 'social_new_value_' + _newindex).attr('name', 'social_new_value_' + _newindex)
-                        ;
-
-                        _dropdown();
-                    });
-                });
-            </script>
     {% endblock %}
 </div>
 {% else %}
diff --git a/galette/templates/default/elements/js/choose_social.js.twig b/galette/templates/default/elements/js/choose_social.js.twig
new file mode 100644 (file)
index 0000000..1f3d69a
--- /dev/null
@@ -0,0 +1,40 @@
+var _dropdownSocials = function() {
+    $('.socials-dropdown').dropdown({
+        allowAdditions: true,
+        onNoResults: function(searchValue) {
+            $(this).dropdown('set value', searchValue);
+        }
+    });
+}
+
+var _rmSocial = function(elt) {
+    if ( typeof elt == 'undefined') {
+        elt = $('#social .stored');
+    }
+    elt.find('.delsocial').click(function(e){
+        e.preventDefault();
+        var _this = $(this);
+        _this.parents('.field.stored').remove();
+    });
+}
+
+$(function(){
+    _rmSocial();
+    _dropdownSocials();
+
+    $('a.addsocial').click(function(e) {
+        e.preventDefault();
+
+        var _newindex = $(this).parents('.addsocial').find('.combo-social:last .socials-dropdown').attr('id').replace('social_new_type_', '');
+        ++_newindex;
+        $(this).parents('.addsocial').find ('.combo-social:last')
+            .clone() // copy
+            .insertAfter('#social .combo-social:last') // where
+            .find('.socials-dropdown').attr('id', 'social_new_type_' + _newindex).dropdown('clear')
+            .find('input:not(.search)').attr('id', 'social_new_type_input_' + _newindex).attr('name', 'social_new_type_' + _newindex)
+            .parent().parent().parent().find('input.value').attr('id', 'social_new_value_' + _newindex).attr('name', 'social_new_value_' + _newindex).val('')
+        ;
+
+        _dropdownSocials();
+    });
+});
index b126da53e61fe05533c45af0d9ea26e98a5a2d9d..e3cd2b3ac7c1adb82bd4510073e7ca5307da9945 100644 (file)
 {% block javascripts %}
         <script type="text/javascript">
             {% include "elements/js/choose_adh.js.twig" with {"js_chosen_id": "#parent_id"} %}
+            {% include "elements/js/choose_social.js.twig" %}
 
             $(function() {
                 $('#company_field.nocompany').addClass('displaynone');
index 965a44f949de99abe7f246d1f0476a6e4abc354d..5a8eef96bc56a06d5edcaab4067460a487290dd1 100644 (file)
 
 {% block javascripts %}
         <script type="text/javascript">
+            {% include "elements/js/choose_social.js.twig" %}
+
             $(function(){
     {% if pref.pref_mail_method != constant('Galette\\Core\\GaletteMail::METHOD_SMTP') %}
                 $('#smtp_parameters').addClass('displaynone');
index 6a4c7d4b8f572edada50c5b7abea08b7530b2f6c..62edaaead994e298b0627f2efba813f99868d61f 100644 (file)
 /*------------------------
      Search dropdown
 -------------------------*/
+.ui.form .fields .field .ui.input.search input,
+.ui.search.selection.dropdown > input.search {
+  width: 100%;
+}
 .ui.search.selection.paginated.dropdown {
     > .ui.mini.button {
         display: none;
     }
-    > input.search {
-        width: 100%;
-    }
     &.visible > .ui.mini.button {
         display: block;
         margin-right: 0;