Open maartenn opened 10 months ago
The plan is to adjust the JavaScript function responsible for adding new address input fields so that it correctly adds a "-" (remove) button to all new address groups except the first one. The first address group should have the "+" (add) and "Show graph" buttons visible, while subsequent address groups should only display the "-" (remove) button. To achieve this, we will:
addAddressInput()
JavaScript function to clone the last address input group and modify it to include only the "-" (remove) button.<!-- Initial address input group with hidden "-" button -->
<div class="input-group mb-3 addressInputGroup" th:each="address : ${addresses}">
<input th:value="*{address}" type="text" class="form-control" placeholder="Bitcoin Address" aria-label="Bitcoin Address" aria-describedby="basic-addon2" required pattern=".*\S+.*" title="This field is required">
<div class="input-group-append">
<button class="btn btn-outline-secondary addAddressField" type="button">+</button>
<button class="btn btn-outline-secondary" type="submit">Show graph</button>
<button class="btn btn-outline-danger remove-address" type="button" style="display: none;">-</button>
</div>
</div>
function addAddressInput() {
console.log('addAddressInput');
const newInputGroup = $('.addressInputGroup').last().clone();
newInputGroup.find('.input-group-append').empty();
newInputGroup.find('input').val('');
newInputGroup.find('.input-group-append').append('<button class="btn btn-outline-danger remove-address" type="button">-</button>');
$('.addressInputGroup').last().after(newInputGroup);
// Hide the "+" and "Show graph" buttons for all but the first address input group
$('.addAddressField, .addressInputGroup .btn[type="submit"]').not(':first').hide();
// Show the "-" button for all but the first address input group
$('.remove-address').not(':first').show();
}
// Call this function once at the start to ensure the correct buttons are displayed
$(document).ready(function () {
// ... existing code ...
addAddressInput();
// ... existing code ...
});
With the provided code, the initial state of the page will have the correct buttons displayed for the first address input group, and the addAddressInput()
function will ensure that any additional address input groups have the appropriate "-" (remove) button. The "+" (add) and "Show graph" buttons will be hidden for all but the first address input group.
Currently when multiple addresses loaded directly from the controller then these are all shown in the overview. That is ok, the problem is that every button has a plus button and generate, i would those not to be displayed and instead a minus button, just as is used when a button is added via Javascript. @autopilot