Skip to content

Instantly share code, notes, and snippets.

@xmunoz
Last active November 24, 2016 15:18
Show Gist options
  • Save xmunoz/dddb174d533fdf84d147de73ccd80d68 to your computer and use it in GitHub Desktop.
Save xmunoz/dddb174d533fdf84d147de73ccd80d68 to your computer and use it in GitHub Desktop.
let buttons = `<button type="button" class="btn btn-warning lessFields"><span class="glyphicon glyphicon-minus"></span></button>
<button type="button" class="btn moreFields"><span class="glyphicon glyphicon-plus"></span></button>`;
prefillFields();
$(".moreFields").click(function() {
console.log("on click moreFields");
// TODO: refactor to permit more than 10 filters
var step = parseInt($(".moreFields").parent().get(0).id.slice(-1)[0]);
addNewField(step + 1);
this.remove();
});
$(".lessFields").click(function() {
var step = parseInt($(".lessFields").parent().get(0).id.slice(-1)[0]) - 1;
$(".lessFields").parent().remove();
$(`.group${step}`).append(buttons);
});
function addNewField(count) {
var html = `<div class="row" id="group${count}">
<input autocomplete="off" type="text" class="form-control fieldKey" name="field${count}" placeholder="Instance Feature" required>
<select class="form-control comparator" name="comparator${count}" required>
<option value="==">=</option>
<option value="!=" >!=</option>
<option value="<">&lt;</option>
<option value="<=">&lt;=</option>
<option value=">">&gt;</option>
<option value=">=">&gt;=</option>
</select>
<input autocomplete="off" type="text" class="form-control fieldValue" name="value${count}" required>`
html = html + buttons + "</div>"
$(".statsFormFields").append(html);
initializeTypeahead(count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment