current view of page how i want it to be
I have made a system in a form where I can add and remove rows, but I just can't get the visual part of it right. I have added two pictures of how it is currently and how I wan't it to be. I used this
post for help, but I didn't get much further.
Here is some of the relevant code: CSS:
.custom-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.custom-container-child {
flex: 1 0 51%;
}
HTML:
<div class="form-group custom-container" id="urlInputs">
<label asp-for="ItemOptionDTO.ItemPicturesWithOptionDTO" class="control-label custom-container-child"></label>
<button id="addRow" class="button btn-primary custom-container-child" type="button">
Add URL
</button>
<input asp-for="ItemOptionDTO.ItemPicturesWithOptionDTO" class="form-control custom-container-child"/>
</div>
JavaScript:
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
<script type="text/javascript">
var counter = 0;
$(function () {
$('#addRow').click(function () {
$('<input id="inputrow' + counter + '" class="form-control custom-container-child" id="ItemOptionDTO.ItemPicturesWithOptionDTO" name="ItemOptionDTO.ItemPicturesWithOptionDTO" type="text">'
+ '<button id="input-row-button' + counter + '" type="button" class="btn btn-primary custom-container-child" onclick="removeRow(' + counter + ');">Delete</button>').appendTo('#urlInputs');
counter++;
return false;
});
});
function removeRow(index) {
if (counter > 0) {
$('#inputrow' + index).remove();
$('#input-row-button' + index).remove();
counter--;
}
return false;
}
</script>
}