Skip to content
Browse files

ENHANCEMENT Updating TreeDropdownField title when hidden form value i…

…s changed
  • Loading branch information...
1 parent b5c739e commit 6bafc76118220b3f1bf4e963e2c034df0c98f402 @chillu chillu committed
Showing with 30 additions and 1 deletion.
  1. +30 −1 javascript/TreeDropdownField.js
View
31 javascript/TreeDropdownField.js
@@ -114,9 +114,29 @@
getTitle: function() {
return this.find('.treedropdownfield-title').text();
},
+ /**
+ * Update title from tree node value
+ */
+ updateTitle: function() {
+ var self = this, tree = self.find('.tree-holder');
+ var updateFn = function() {
+ var val = self.getValue();
+ if(val) {
+ var node = tree.find('*[data-id="' + val + '"]'),
+ title = (node) ? tree.jstree('get_text', node[0]) : null;
+
+ if(title) self.setTitle(title);
+ if(node) tree.jstree('select_node', node);
+ }
+ };
+
+ // Load the tree if its not already present
+ if(jQuery.jstree._reference(tree)) updateFn();
+ else this.loadTree(null, updateFn);
+ },
setValue: function(val) {
this.find(':input:hidden').val(val);
-
+ this.updateTitle();
this.trigger('change');
},
getValue: function() {
@@ -331,6 +351,15 @@
},
setTitle: function(title) {
this._super($.isArray(title) ? title.join(', ') : title);
+ },
+ updateTitle: function() {
+ // TODO Not supported due to multiple values/titles yet
+ }
+ });
+
+ $('.TreeDropdownField input[type=hidden]').entwine({
+ onchange: function() {
+ this.getField().updateTitle();
}
});
});

0 comments on commit 6bafc76

Please sign in to comment.
Something went wrong with that request. Please try again.