{"id":970,"date":"2024-04-16T03:58:41","date_gmt":"2024-04-15T18:58:41","guid":{"rendered":"http:\/\/inwelly.com\/?p=970"},"modified":"2024-04-22T05:05:03","modified_gmt":"2024-04-21T20:05:03","slug":"javascript-%eb%a9%80%ed%8b%b0-select2-on-bootstrap","status":"publish","type":"post","link":"https:\/\/inwelly.com\/?p=970","title":{"rendered":"JAVASCRIPT \uba40\ud2f0 select2 on bootstrap"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;\/css\/select2.min.css&#8221;><\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\/\/ \uc2e4\ud589 --------------------------------------------------------------------------------<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&lt;select class=&#8221;form-control select2 select2-hidden-accessible&#8221; disabled id=&#8221;TM_PERIOD&#8221; name=&#8221;TM_PERIOD&#8221; multiple=&#8221;&#8221; data-placeholder=&#8221;select the time&#8221; style=&#8221;width: 300px;&#8221; tabindex=&#8221;-1&#8243; aria-hidden=&#8221;true&#8221;&gt;<\/p>\n\n\n\n<p>&lt;option value=&#8221;A&#8221; &gt;\uc804\uccb4&lt;\/option&gt;<\/p>\n\n\n\n<p>&lt;option value=&#8221;01&#8243; &gt;01~02&lt;\/option&gt;<\/p>\n\n\n\n<p>&lt;option value=&#8221;02&#8243; &gt;02~03&lt;\/option&gt;<\/p>\n\n\n\n<p>&lt;option value=&#8221;03&#8243; &gt;03~04&lt;\/option&gt;<\/p>\n\n\n\n<p>&lt;\/select&gt;<\/p>\n\n\n\n<p>&lt;script&gt;<\/p>\n\n\n\n<p>$(function(){<\/p>\n\n\n\n<p>\/\/Initialize Select2 Elements<\/p>\n\n\n\n<p>$(&#8216;.select2&#8217;).select2()<\/p>\n\n\n\n<p>});<\/p>\n\n\n\n<p>&lt;\/script&gt;<\/p>\n\n\n\n<p>&lt;script src=&#8221;\/js\/select2.full.min.js&#8221; &gt;&lt;\/script&gt;<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\/\/ \uc2e4\ud589 \uc804\ub2ec  --------------------------------------------------------------------------------<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&lt;input type=text id=&#8221;final_show_tm_arr&#8221; name=&#8221;final_show_tm_arr&#8221;&gt;<\/p>\n\n\n\n<p>&lt;script&gt;<\/p>\n\n\n\n<p>&nbsp;var ARR_ALL_SHOWTM&nbsp; = new Array ;<\/p>\n\n\n\n<p>&nbsp;var ARR_EACH_SHOWTM = new Array ;<\/p>\n\n\n\n<p>&nbsp;var CHK_ALL = 0 ;<\/p>\n\n\n\n<p>&nbsp;$.makeArray($(&#8220;li&#8221;).map(function(){<\/p>\n\n\n\n<p>&nbsp;var liMap = $(this).attr(&#8220;title&#8221;) ;<\/p>\n\n\n\n<p>&nbsp;if(typeof liMap == &#8220;undefined&#8221;){<\/p>\n\n\n\n<p>&nbsp;}<\/p>\n\n\n\n<p>&nbsp;else<\/p>\n\n\n\n<p>&nbsp;{<\/p>\n\n\n\n<p>&nbsp;if( liMap == &#8216;\uc804\uccb4&#8217; )<\/p>\n\n\n\n<p>&nbsp;{<\/p>\n\n\n\n<p>&nbsp; &nbsp; $(&#8220;#TM_PERIOD option&#8221;).each&nbsp; ( function()&nbsp;<\/p>\n\n\n\n<p>&nbsp; &nbsp; {<\/p>\n\n\n\n<p>&nbsp; if( $(this).val() !=&#8221;A&#8221; )<\/p>\n\n\n\n<p>&nbsp; {<\/p>\n\n\n\n<p>&nbsp; \/\/ console.log(&#8220;all option :&#8221;+$(this).val());<\/p>\n\n\n\n<p>&nbsp; ARR_ALL_SHOWTM.push ( $(this).val() );<\/p>\n\n\n\n<p>&nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; });<\/p>\n\n\n\n<p>&nbsp;CHK_ALL++;<\/p>\n\n\n\n<p>&nbsp;return false;<\/p>\n\n\n\n<p>&nbsp;}<\/p>\n\n\n\n<p>&nbsp;else<\/p>\n\n\n\n<p>&nbsp;{<\/p>\n\n\n\n<p>&nbsp;ARR_EACH_SHOWTM.push(liMap.substring( 0, 2 ));<\/p>\n\n\n\n<p>&nbsp;\/\/ console.log(&#8220;select option without A :&#8221;+liMap.substring( 0, 2 ));<\/p>\n\n\n\n<p>&nbsp;}<\/p>\n\n\n\n<p>&nbsp;}<\/p>\n\n\n\n<p>}));<\/p>\n\n\n\n<p>$(&#8220;#final_show_tm_arr&#8221;).val(ARR_EACH_SHOWTM);<\/p>\n\n\n\n<p>&lt;\/script&gt;<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\/ \ub370\uc774\ud130\ubca0\uc774\uc2a4\uc5d0\uc11c \ub098\uc628\uac83\uc744 \ub2e4\uc2dc \uc801\uc6a9 -----------------------------------------------<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&lt;script&gt;<\/p>\n\n\n\n<p>var INVENSTR = &#8220;01,02,03&#8221;;<\/p>\n\n\n\n<p>if(INVENSTR)<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>function sliceFn(val)<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>var str = val ;<\/p>\n\n\n\n<p>str = &#8220;00&#8221; + str ;<\/p>\n\n\n\n<p>str = str.slice(-2);<\/p>\n\n\n\n<p>return str;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>var invenVal = INVENSTR ;<\/p>\n\n\n\n<p>var arr = invenVal.split(&#8220;,&#8221;);<\/p>\n\n\n\n<p>var arr_val = 0 ;<\/p>\n\n\n\n<p>var arr_val_add = 0 ;<\/p>\n\n\n\n<p>var inputarr = &#8220;&#8221; ;<\/p>\n\n\n\n<p>var inputarrX = [] ;<\/p>\n\n\n\n<p>var inputarrY = new Array;<\/p>\n\n\n\n<p>var val_sum = &#8220;&#8221;;<\/p>\n\n\n\n<p>$.each(arr, function(i, obj)<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>inputarrY.push(arr[i]);<\/p>\n\n\n\n<p>arr_val = arr[i] * 1 ;<\/p>\n\n\n\n<p>inputarrX.push(arr_val);<\/p>\n\n\n\n<p>})<\/p>\n\n\n\n<p>if( inputarrX.length == 3 )&nbsp;<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>var $PeriodMulti = $(&#8220;.select2-hidden-accessible&#8221;).select2();<\/p>\n\n\n\n<p>$PeriodMulti.val([&#8220;A&#8221;]).trigger(&#8220;change&#8221;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>else<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>var $PeriodMulti = $(&#8220;.select2-hidden-accessible&#8221;).select2();<\/p>\n\n\n\n<p>$PeriodMulti.val(inputarrY).trigger(&#8220;change&#8221;);<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>&lt;\/script&gt;<\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"383\" height=\"297\" src=\"http:\/\/inwelly.com\/wp-content\/uploads\/2024\/04\/image-482.png\" alt=\"\" class=\"wp-image-971\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;\/css\/select2.min.css&#8221;> &lt;select class=&#8221;form-control select2 select2-hidden-accessible&#8221; disabled id=&#8221;TM_PERIOD&#8221; name=&#8221;TM_PERIOD&#8221; multiple=&#8221;&#8221; data-placeholder=&#8221;select the time&#8221; style=&#8221;width: 300px;&#8221; tabindex=&#8221;-1&#8243; aria-hidden=&#8221;true&#8221;&gt; &lt;option value=&#8221;A&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1279,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-970","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=970"}],"version-history":[{"count":1,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/970\/revisions"}],"predecessor-version":[{"id":972,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/970\/revisions\/972"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/media\/1279"}],"wp:attachment":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}