V
V
viktorross2019-06-17 02:13:54
PHP
viktorross, 2019-06-17 02:13:54

How to output foreach loop in select2 or choosen?

hello, please help me solve the problem.
Regions are displayed here in 3 columns, if you select a region, then possible cities appear,
so when you try to remove all this heresy and display it in a regular select2 or choosen, nothing happens, or an error, tell me who understands this smarty, which parts of the cycles to remove , and what should be left for normal output in select.
In fact, I just need to take cycles from here and output instead of ul in select ..
I tried like this:

{foreach from=$fields item=v name=f}
  
  {if $v.type=="depending"}
  <select class="tests45" style="width: 100%;">
    {foreach from=$v.elements item=e name=el}
<option value="" id="{$v.caption}{$e.id}" class="mlink {if $type=='double'}dep_selector{/if}{if $location_array[$v.caption]==$e.name} bold underline{/if}" 
{if $type!="double"}onclick='changeLocation("{$live_site}", "{$settings.location_fields}|{$e.name}")'{/if}>{$e.name}{if $e.no>0} <!--({$e.no})--> {/if}</option>
{/foreach}
</select>
{/if}

The script itself
<div id="locations_list">

<form name="set_location" id="set_location" method="post" action="">

{* one location field *}
{if ','|explode:$settings.location_fields|@count==1}

{assign var="type" value="single"}
<input type="hidden" name="direct" id="direct" value="1" />
<input type="hidden" name="field" id="field" value="{$settings.location_fields}" />
<input type="hidden" name="location" id="location" value="" />

{else}{* input fields for each of the location fields *}

{assign var="type" value="double"}

{* the list is used when deleting a location to clear the next depending locations also *}
<input type="hidden" name="locations_array" id="locations_array" value="{foreach from=$fields item=v name=f}{if $smarty.foreach.f.index!=0}|{/if}{$v.caption}^{$v.name}{/foreach}" />

{foreach from=$fields item=v name=f}
<input type="hidden" name="{$v.caption}" id="{$v.caption}" value="{$location_array[$v.caption]}" />
<input type="hidden" name="{$v.caption}_id" id="{$v.caption}_id" value="" />
{if $v.type=="depending"}
<input type="hidden" name="{$v.caption}_dep_id" id="{$v.caption}_dep_id" value="{$v.dep_id}" />
<input type="hidden" name="{$v.caption}_table" id="{$v.caption}_table" value="{$v.table}" />
{/if}
{/foreach}

{/if} {* end double *}


{foreach from=$fields item=v name=f}

  <div class="mt20">
  <div class="lfloat heading"><span class="sdffe_HJ778" style="line-height: 50px;">{$v.name}</span></div>
  <div class="delete_location rfloat mt15"><a href='javascript:;' class="link_delete_location" id="delete{if $type=="double"}_{$v.caption}{/if}"><img src="{$template_path}images/delete.png" id="img_delete{if $type=="double"}_{$v.caption}{/if}" {if !$location_array[$v.caption]}class="low_op"{/if}/></a></div>
  <div class="clearfix"></div>
  
  <div class="loc_selector" id="div_{$v.caption}">
  {if $v.type=="depending"}

    <ul class="nolist list1">
    {if $v.elements|@count>0}
    {assign var="c" value="1"}
    {foreach from=$v.elements item=e name=el}
    <li style="margin-bottom: 7px;" class="mlink {if $type=='double'}dep_selector{/if}{if $location_array[$v.caption]==$e.name} bold underline{/if}" id="{$v.caption}{$e.id}" {if $type!="double"}onclick='changeLocation("{$live_site}", "{$settings.location_fields}|{$e.name}")'{/if}><span style="border-bottom:1px solid #09f;">{$e.name}</span>{if $e.no>0} <!--({$e.no})--> {/if}</li>
    {if $smarty.foreach.el.index==$c*$v.no_per_column-1}
    </ul>
    <ul class="nolist list1">
    {assign var="c" value=$c+1}
    {/if}
    {/foreach}
    {else}
    {$lng.location.choose} {$v.name}
    {/if}
    </ul>
    <div class="clearfix"></div>
  {else}

    <ul class="nolist list1">
    {assign var="c" value="1"}
    {foreach from=$v.elements item=e name=el}
    <li class="mlink menu_selector{if $location_array[$v.caption]==$e} bold underline{/if}" style="margin-bottom: 7px;"><span>{$e}</span></li>
    {if $smarty.foreach.el.index==$c*$v.no_per_column-1}
    </ul>
    <ul class="nolist list1">
    {assign var="c" value=$c+1}
    {/if}
    {/foreach}
    </ul>
    <div class="clearfix"></div>
  {/if}
  </div> {* end loc_selector *}
  </div> {* end loc_holder *}
{/foreach}

  <div class="clearfix"></div>
  
  {if $type=="double"}
  <div class="rfloat mt20">
  <input type="submit" class="button" name="Save" id="Save" value="{$lng.location.save_location}" />
  </div>
  <div class="clearfix"></div>
  {/if}

</form>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question