Semantic ui combobox

I use the semantic-ui concept for my project. I need a combobox function, so I'm trying to combine text input and a semantics popup menu.

My requirements:
1) Accept values ​​that are not in the drop-down list
2) Perform a text input check (for example, without spaces)
3) Select / Search versus drop-down menu

See: http://plnkr.co/edit/d5IUrqfHyjLy0qcH4qYQ?p=preview

<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/1.8.1/semantic.min.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/1.8.1/semantic.min.js"></script> <script src="script.js"></script> </head> <body> <h4 class="ui inverted black block header"><span>semantic ui</span></h4> <div class="ui grid"> <div class="eight wide centered column"> <form class="ui form ui form segment"> <h4 class="ui dividing header">Personal Information</h4> <div class="field"> <div class="ui icon input search dropdown"> <input type="text" id="jheader" data-validate="header" placeholder="Enter header" ng-model="person.gender"> <i class="dropdown icon link"></i> <div class="menu"> <div class="item">Clothing</div> <div class="item">Home Goods</div> <div class="item">Bedroom</div> <div class="item">Status</div> <div class="item">Cancellations</div> </div> </div> </div> </form> </div> </div> <script> $(document).ready(function() { $('.ui.dropdown').dropdown({ onChange: function(value, text, $selectedItem) { $("#jheader").val(text).trigger('input'); } }); console.log("ready!"); }); </script> </body> </html> 

I need to enable a drop-down search when I enter values ​​in an input.

+6
source share
2 answers

I had almost the same problem a while ago.

Here is an example of what I did with mine to fulfill requirement 1) and 3). http://plnkr.co/edit/4nC44UETWhPb8yVNNtKz?p=preview

The code is also pasted below, but without a massive block of comments. Basically, how it works, it uses a semantic user interface, which includes a drop-down list of choices, i.e. "Search Select", and uses blur to set the hidden text field that you send.

The reason you need to set the hidden text box using code is the semantic user interface, which creates a second text box with the “search” class, which users will see and enter data, but are not actually represented.

There is also other additional code to solve other problems, see the comments in the plunker link above. To deal with one of them, I had to remove the automatically generated “active” class from the drop-down div options, which led to an effect without bias for the selected item in the drop-down list.

HTML

  <div class="customDropdownSearchTextInput ui search selection dropdown"> <input type="hidden" name="gender"> <div class="default text">Gender</div> <i class="dropdown icon"></i> <div class="menu"> <div class="item" data-value="Male">Male</div> <div class="item" data-value="Female">Female</div> </div> </div> 

Javascript

 $('.ui.dropdown').dropdown(); $(".customDropdownSearchTextInput").each(function(){ var defaultText = false; if ( $(this).find(".text").hasClass("default") && $(this).find(".text").text() ) defaultText = $(this).find(".text").text(); var isSelectTag = false; if ( $(this).find("input:hidden").length < 1 || $(this).addBack().find( "select" ).length > 0 ) isSelectTag = true; if ( isSelectTag == false ) { $(this).dropdown( { forceSelection: false }); $(this).find(".search").on("focus", function(event){ var aOpt = $(this).parent().find(".active"); aOpt.removeClass("active"); }); var originalText = $(this).find(".search").text(); $(this).find(".search").on("blur", function(event){ var text = $(this).val(); if ( originalText != text ) { if ( $.trim(text)=="" && defaultText != false ) { $(this).parent().find(".text").addClass("default").removeClass("filtered").text(defaultText); } $(this).parent().find("input:hidden").val(text); originalText = text; } }); } }); 
+2
source

Unfortunately, Semantic-UI does not have this feature until the latest version 1.12.x.

The behavior of "ui search selection dropdown" very different from the actual behavior of combox.

0
source

Source: https://habr.com/ru/post/981693/


All Articles