diff --git a/css/taxonomy.css b/css/taxonomy.css
index e45d2dfa5..3deb31d6b 100644
--- a/css/taxonomy.css
+++ b/css/taxonomy.css
@@ -1,4 +1,12 @@
li ul.rw-taxonomy-tree {
margin-left: 15px;
margin-top: 5px;
+}
+
+div.rw-taxonomy-tree.active{
+ display:inline-block;
+}
+
+div.rw-taxonomy-tree.disabled{
+ display:none;
}
\ No newline at end of file
diff --git a/demo/field-taxonomy.php b/demo/field-taxonomy.php
index 0a525f534..94b190281 100644
--- a/demo/field-taxonomy.php
+++ b/demo/field-taxonomy.php
@@ -69,7 +69,8 @@ static function normalize_field( $field )
$field['field_name'] = "{$field['field_name']}[]";
}
- if($field['options']['type'] == 'checkbox_tree'){
+ if($field['options']['type'] == 'checkbox_tree' || $field['options']['type'] == 'select_tree'){
+ $field['field_name'] = $field['field_name'] . '[]';
if(isset($field['options']['args']['parent']))
{
$field['options']['parent'] = $field['options']['args']['parent'];
@@ -117,6 +118,12 @@ static function html( $html, $meta, $field )
$elements = self::process_terms($terms);
$html .= self::walk_checkbox_tree($meta, $field, $elements, $field['options']['parent'], true);
}
+ //Select Tree
+ elseif ( 'select_tree' == $options['type'] )
+ {
+ $elements = self::process_terms($terms);
+ $html .= self::walk_select_tree($meta, $field, $elements, $field['options']['parent'], '', true);
+ }
// Select
else
{
@@ -147,22 +154,58 @@ static function walk_checkbox_tree( $meta, $field, $elements, $parent = 0, $acti
if(!isset($elements[$parent]))
return;
$terms = $elements[$parent];
- $html = '';
- $hidden = ! $active ? ' hidden' : '';
-
- if ( ! empty( $terms ) )
+ $hidden = ( !$active ? 'hidden' : '' );
+
+ $html = "
";
+
+ return $html;
+ }
+
+ /**
+ * Walker for displaying select in treeformat
+ *
+ * @param $meta
+ * @param $field
+ * @param bool $active
+ *
+ * @return string
+ */
+ static function walk_select_tree( $meta, $field, $elements, $parent = 0, $parent_slug='', $active = false )
+ {
+ echo $parent;
+ if(!isset($elements[$parent]))
+ return;
+ $terms = $elements[$parent];
+ $hidden = ( !$active ? 'disabled' : 'active' );
+ $disabled = disabled($active, false, false); ;
+ $multiple = $field['multiple'] ? " multiple='multiple' style='height: auto;'" : "'";
+ $id = '';
+ if(!empty($parent_slug))
+ {
+ $id = "id='rwmb-taxonomy-{$parent_slug}'";
+ }
+ $html = "";
+ $html .= "";
+ foreach ( $terms as $term )
+ {
+ $html .= self::walk_select_tree($meta, $field, $elements, $term->term_id, $term->slug, (in_array( $term->slug, $meta)) && $active) . "";
+ }
+ $html .= "
";
+
return $html;
}
diff --git a/js/taxonomy.js b/js/taxonomy.js
index 466ebd5e0..da620a515 100644
--- a/js/taxonomy.js
+++ b/js/taxonomy.js
@@ -12,4 +12,16 @@ jQuery( document ).ready( function($)
$childList.addClass( 'hidden' );
}
} );
+
+ $( '.rw-taxonomy-tree select' ).change( function()
+ {
+ var $this = $( this ),
+ $childList = $this.parent().find( 'div.rw-taxonomy-tree' ),
+ $value = $this.val();
+ $childList.removeClass('active').addClass('disabled').find('select').each(function(){
+ $(this).val($('options:first', this).val()).attr("disabled", "disabled")
+ });
+ $childList.filter('#rwmb-taxonomy-' + $value).removeClass('disabled').addClass('active').children('select').removeAttr('disabled');
+
+ } );
} );
\ No newline at end of file