Closed chamster closed 7 years ago
That won't work because #auto-checkboxes
doesn't exist in the DOM when the call to .bonsai()
is made. You can simply wrap that in an onload
callback to fix:
$(function() { // this will be executed on load
$('#auto-checkboxes').bonsai({...
Thanks so much for the reply. However, still no luck. To keep it simpler I've stripped it down to just the one small tree. Here's what I have now:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Bonsai Test</title>
<link rel='stylesheet' type='text/css' href='https://github.jspm.io/aexmachina/jquery-bonsai@master/jquery.bonsai.css' />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src='/jquery-bonsai/jquery.bonsai.js'></script>
<script src='/jquery-bonsai/jquery.qubit.js'></script>
<script type="text/javascript">
$(function() { // this will be executed on load
$('#auto-checkboxes').bonsai({
expandAll: false,
checkboxes: true, // depends on jquery.qubit plugin
createCheckboxes: true // takes values from data-name and data-value, and data-name is inherited
})
});
</script>
</head>
<body>
<ol id='auto-checkboxes' data-name='foo'>
<li class='expanded' data-value='0'>All
<ol>
<li data-value='1'>One</li>
<li data-value='2'>
Two
<ol>
<li data-name='baz' data-value='3'>
Three
<ol>
<li data-name='baz' data-value='4' data-checked='1'>Four</li>
</ol>
</li>
<li data-value='5'>Five</li>
</ol>
</li>
</ol>
</li>
</ol>
</body>
</html>
Works fine for me: https://jsfiddle.net/mpj57s5x/
Check out the Chrome Dev Tools for any Network or JavaScript errors in the Console tab.
Awesome, thanks! My paths to js files were screwed up. Working now. Cheers!
Can I use this as input in a form? I'd like the user to select one of the items via radio button, then pass the selected value to be processed when the form is submitted. The html is all ol's and li's but no input. Will I need to do some custom javascript to make this possible? Thanks.
Yes, you can specify createInputs: 'radio'
. There some basic docs here
I've done that:
<script type="text/javascript"> $(function() { // this will be executed on load $('#auto-radio-buttons').bonsai({ expandAll: false, createInputs: 'radio' }) }); </script>
It does make radio buttons. And the rendered html is like:
`
May I suggest you spend some more time learning how to use the tools you're using :) If you want to put an HTML block in a Github comment (Markdown) you need to use triple-backticks. See here for more info: https://guides.github.com/features/mastering-markdown/
As indicated in the docs: The id, name and value for the inputs can be declared in the
markup using data-id
, data-name
and data-value
:
<li data-name='foo' data-value='1'>One</li>
<li data-name='foo' data-value='2'>Two</li>
Hi. I'm trying to get a simple test working. But all I get when rendered is the nested list. Not collapsible or checkboxes. My code is pasted below. Am I missing something? Thanks.