-
-
Save whroman/f5cdc33309ea7e6ef7ba3d74d380cccb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
bindMoreFieldsClickHandler(); | |
function bindMoreFieldsClickHandler() { | |
$(".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(); | |
bindMoreFieldsClickHandler(); | |
}); | |
} | |
$(".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="<"><</option> | |
<option value="<="><=</option> | |
<option value=">">></option> | |
<option value=">=">>=</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