From: Vincent Vanwaelscappel Date: Tue, 7 Jun 2022 11:39:24 +0000 (+0200) Subject: wip #5301 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=19836ac2a4f158000038021533cdebea9122e8f4;p=cubist_cms-back.git wip #5301 @3 --- diff --git a/src/public/bunchmultiple/bunchmultiple.js b/src/public/bunchmultiple/bunchmultiple.js index 5a256d8..746dc0e 100644 --- a/src/public/bunchmultiple/bunchmultiple.js +++ b/src/public/bunchmultiple/bunchmultiple.js @@ -211,7 +211,7 @@ }, initItem: function (values) { - console.log(values); + var $this = this; var collapsed = true; var isNew = false; @@ -269,13 +269,24 @@ try { $.each(values, function (k, v) { var input = $(item).find('[name="' + id + '___' + k + '"]'); + if (input.is('.hiddenfield')) { $(input).parent().attr('data-values', JSON.stringify(v)); } else if ($(input).nextAll('[type="checkbox"]').length > 0) { var cb = $(input).nextAll('[type="checkbox"]'); cb.attr('name', cb.prev('[type="hidden"]').attr('name')).attr('value', '1'); cb.prop('checked', v === true || v === '1' || v === 1); - } else { + } else if ($(input).is('.select2_from_array')) { + try { + if ($(input).data('ajax')!==null && $(input).find('option[value="' + k + '"]').length === 0) { + var options = $(input).data('options'); + var newOption = new Option(options[v], v, false, false); + $(input).append(newOption).trigger('change'); + } + } catch (e) { + } + input.val(v); + } else if (input) { input.val(v); } }); diff --git a/src/resources/views/fields/select2_from_array.blade.php b/src/resources/views/fields/select2_from_array.blade.php index c1a31e5..a04b178 100644 --- a/src/resources/views/fields/select2_from_array.blade.php +++ b/src/resources/views/fields/select2_from_array.blade.php @@ -1,16 +1,15 @@ @php $o=$field['value'] ?? old(square_brackets_to_dots($field['name']))??$field['default']; - $is_null=null===$o; + $is_null=null===$o || $o==='null'; if(!function_exists('select2_from_array_selected')){ function select2_from_array_selected($key,$o){ - if(null===$o){ + if(null===$o || $o==='null'){ return false; } if(!is_array($o)){ return $o==$key; - } - if(is_array($o)){ + }else { return in_array($key,$o); } return false; @@ -38,6 +37,7 @@ if($ajax){ @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)multiple @endif @if($ajax) data-ajax="{{$field['ajax']}}" @endif @if($allows_html) data-allow-html="1" @endif + data-options="{{ json_encode($field['options']) }}" > @if (isset($field['allows_null']) && $field['allows_null']==true) @if($is_null) @@ -49,17 +49,13 @@ if($ajax){ @if (count($field['options'])) @foreach ($field['options'] as $key => $value) - @php - $selected=select2_from_array_selected($key,$o); - @endphp - @if($selected) + @if(!$is_null && select2_from_array_selected($key,$o)) @elseif(!$ajax) @endif @endforeach @endif - {{-- HINT --}} diff --git a/src/resources/views/when.blade.php b/src/resources/views/when.blade.php index 2084f0e..9ef1945 100644 --- a/src/resources/views/when.blade.php +++ b/src/resources/views/when.blade.php @@ -1,137 +1,145 @@ @push('crud_fields_scripts') - + @endpush @push('crud_fields_styles') - + .when-visible[data-when] { + display: block; + } + @endpush