I try to build UI for labels and checkboxes dynamically
My idea is to build it like this
<div class="form-group col-lg-3 col-md-3 col-sm-6">
<label for="HideVerifiedTickets" class="m-checkbox mt-35px">
<input id="HideVerifiedTickets" class="filter" type="checkbox" name="HideVerifiedTickets" />
HideVerifiedTickets
<span></span>
</label>
</div>
In the js
file I wrote it like this
function renderCheckbox(ui, uiField, labelText, idField, nameOnForm){
let id = abp.helper.getUniqueElementId();
let container = $('<div class="form-group col-lg-3 col-md-3 col-sm-6">');
let label = $('<label class="m-checkbox mt-35px">').attr('for', idField).text(labelText);
let checkbox = $('<input type="checkbox" class="filter">').attr('name', nameOnForm).attr('id', idField);
checkbox.appendTo(label);
let result = container.append(label);
return result;
}
but the problem is that it generates HTML like this
How can I move text after the checkbox?
2
Answers
You can use
.prependTo()
rather than.appendTo()
to put a check-box before the text.Also, you can do it in one go with
.append()
Instead of creating a new variable, assigning the whole HTML, and returning it, you can directly return the container variable that holds the desired HTML.
So the code should be:
Note:
the first 2 parameters of the function are not used at all, so you can remove them.
Also
let id = abp.helper.getUniqueElementId();
seems to be of no-use so you can remove it too.You can create a textNode using the createTextNode() method and append it to the label just like you do with the checkbox.
In the example I removed the
for
attribute and the ID for the input element because they are probably not needed.