Fix rendering of Add Value attributes when the attribute is also rendered by a template, resulting in double javascript and blank values

This commit is contained in:
Deon George 2025-07-03 13:02:02 +08:00
parent 06747064d4
commit 46277146c5
4 changed files with 8 additions and 8 deletions

View File

@ -46,7 +46,7 @@
</span>
@endif
@if((! $o->no_attr_tags) && (! $o->is_rdn))
@if((! $o->no_attr_tags) && (! $o->is_rdn) && (! $template))
<span data-bs-toggle="tab" href="#langtag-{{ $o->name_lc }}-+" class="bg-primary-subtle btn btn-outline-primary border-primary addable d-none">
<i class="fas fa-fw fa-plus text-dark" data-bs-toggle="tooltip" data-bs-custom-class="custom-tooltip" aria-label="Add Lang Tag" data-bs-original-title="Add Lang Tag"></i>
</span>

View File

@ -1,5 +1,5 @@
<!-- $o=Attribute::class -->
<x-attribute.layout :edit="$edit=($edit ?? FALSE)" :new="$new=($new ?? FALSE)" :o="$o">
<x-attribute.layout :edit="$edit=($edit ?? FALSE)" :new="$new=($new ?? FALSE)" :o="$o" :template="$template">
<div class="col-12">
<div class="tab-content">
@foreach($o->langtags as $langtag)

View File

@ -4,7 +4,7 @@
{{ $slot }}
</attribute>
<x-attribute.widget.options :o="$o" :edit="$edit" :new="$new"/>
<x-attribute.widget.options :o="$o" :edit="$edit" :new="$new" :template="$template ?? FALSE"/>
</div>
</div>

View File

@ -255,18 +255,18 @@
@default
@if($o->isDynamic()) @break @endif
@php($clone=TRUE)
@if($o->values_old->count())
<span @class(['btn','btn-sm','btn-outline-primary','mt-3','addable','d-none'=>(! $new)]) data-attribute="{{ $o->name }}" id="{{ $o->name_lc }}-addnew"><i class="fas fa-fw fa-plus"></i> @lang('Add Value')</span>
@if($o->values_old->count() && (! $template))
<span @class(['btn','btn-sm','btn-outline-primary','mt-3','addable','d-none'=>(! $new)]) data-attribute="{{ $o->name_lc }}" id="{{ $o->name_lc }}-addnew"><i class="fas fa-fw fa-plus"></i> @lang('Add Value')</span>
@endif
@section('page-scripts')
@if($clone && $edit && $o->can_addvalues)
@if((! $template) && $clone && $edit && $o->can_addvalues)
<script type="text/javascript">
$(document).ready(function() {
// Create a new entry when Add Value clicked
$('#{{ $o->name_lc }}-addnew.addable').click(function(item) {
$('form#dn-edit #{{ $o->name_lc }}-addnew.addable').click(function(item) {
var attribute = $(this).data('attribute');
var active = $('attribute[id='+attribute+']').find('.tab-pane.active');
var active = $('#template-default attribute[id='+attribute+']');
active.find('input:last')
.clone()