Skip to content

Commit

Permalink
beth-each bugfixes
Browse files Browse the repository at this point in the history
Signed-off-by: rumd3x <[email protected]>
  • Loading branch information
rumd3x committed Feb 2, 2019
1 parent d7b683a commit 5378534
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions beth.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ class Beth {
}
$("[beth-loop-id='"+uniqueId+"']").remove();


if (source === undefined) {
source = [];
}

if (source.length === 0) {
$(this).parent().hide();
console.log('hey');
}

for (let index = 0; index < source.length; index++) {
const element = source[index];
var clone = $(this).clone().removeAttr('beth-each').removeAttr('beth-id').attr('beth-loop-id', uniqueId).unwrap();
Expand Down
9 changes: 7 additions & 2 deletions example/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h4>Beth Dynamic Inputs!</h4>
String in the above input => {{instance.tests.string}}
<br>
<br>
Comboboxes!
Comboboxes!
<select beth-bind="instance.tests.select" beth-change="instance.selectChanged(instance.tests.select)">
<option beth-each="instance.tests.options => $value" value="{$value.value}">{$value.text}</option>
</select>
Expand Down Expand Up @@ -56,7 +56,12 @@ <h4>Beth Dynamic Inputs!</h4>

<p>Sync Partial => <beth-include url="partials/partial_example.html" /></p>
<p>Async Partial => <beth-include-async url="partials/partial_example.html" /></p>

<br><br>

<p beth-each="test_array => $test">{$test}</p>
<button beth-click="test_array.push('New element '+test_array.length)">Add element to array</button>
</body>
<script src="MyTestModel.class.js"></script>
<script src="formcontroller.js"></script>
</html>
</html>
3 changes: 2 additions & 1 deletion example/formcontroller.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var instance = new MyTestModel();
var string_inside = "<b>Testing</b> Beth-Inside <i>directive</i> with and <ul><li>without</li> <li>HTML</li></ul> content!";
var test_array = [];

$(document).ready(function() {
$("#btnGenText").click(function() {
instance.text = Math.random().toString(36).substring(2);
});
});
});

0 comments on commit 5378534

Please sign in to comment.