Fixed field-adder wipes out "value" from numberbox

DragonByte Tech

Well-known member
Affected version
2.0.4
Consider the following HTML:
Code:
<li class="inputPair" data-xf-init="field-adder" data-increment-format="available_products[{counter}]">
    <div class="inputGroup">
        <xf:select name="available_products[{$nextCounter}][product_id]" class="filterBlock-input">
            <xf:option>{{ phrase('(none)') }}</xf:option>
            <xf:foreach loop="{{ $products }}" value="$treeEntry">
                <xf:option value="{$treeEntry.record.product_id}">{{ repeat('--', $treeEntry.depth) }}
                    {$treeEntry.record.title}
                </xf:option>
            </xf:foreach>
        </xf:select>

        <span class="inputGroup-splitter"></span>

        <xf:numberbox name="available_products[{$nextCounter}][available_licenses]" min="-1"
                      step="1" value="-1" required="{{ false }}" />
    </div>
</li>

When refreshing the page, a normal input box with -1 is shown but as soon as the two number box step buttons appear, the value is wiped out.

This does not affect "normal" numberboxes that are not inside a field-adder.


Fillip
 
Technically this is as designed, because you essentially want the cloned input element to always be "reset" and for most purposes, setting the value of it to an empty string is the right way to do that.

That said, I appreciate being able to override that would be useful.

With that in mind, you can now add a data-default-value="-1" attribute to the input element itself, and when it is initialised and cloned it will always get that default value, rather than being cleared:
HTML:
<li class="inputPair" data-xf-init="field-adder" data-increment-format="available_products[{counter}]">
    <div class="inputGroup">
        <xf:select name="available_products[{$nextCounter}][product_id]" class="filterBlock-input">
            <xf:option>{{ phrase('(none)') }}</xf:option>
            <xf:foreach loop="{{ $products }}" value="$treeEntry">
                <xf:option value="{$treeEntry.record.product_id}">{{ repeat('--', $treeEntry.depth) }}
                    {$treeEntry.record.title}
                </xf:option>
            </xf:foreach>
        </xf:select>

        <span class="inputGroup-splitter"></span>

        <xf:numberbox name="available_products[{$nextCounter}][available_licenses]" min="-1"
                      step="1" value="-1" data-default-value="-1" required="{{ false }}" />
    </div>
</li>
 
Oh, side note, when I fixed this, I also noticed that the up/down buttons didn't actually trigger a new field to be added. Fixed that too. Oh and while I was there I fixed a long time annoyance whereby pasting into a field adder field didn't trigger a new field to be added.
 
Back
Top Bottom