do not return folders, if leafOnly is set and some more docu

This commit is contained in:
ralf 2024-08-22 14:18:32 +02:00
parent 3e577c738f
commit c18be4cf4d
4 changed files with 19 additions and 5 deletions

View File

@ -1366,7 +1366,9 @@ export const Et2WithSearchMixin = dedupeMixin(<T extends Constructor<LitElement>
*/ */
protected searchMatch(search : string, option : SelectOption) : boolean protected searchMatch(search : string, option : SelectOption) : boolean
{ {
if(!option || !option.value) if(!option || !option.value ||
// do NOT return folders, if leafOnly is set
this.leafOnly && typeof option.children === 'undefined')
{ {
return false; return false;
} }

View File

@ -97,7 +97,10 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) implements Fin
openIcon: String; openIcon: String;
@property({type: Function}) @property({type: Function})
onclick;// description: "JS code which gets executed when clicks on text of a node" onclick;// description: "JS code which gets executed when clicks on text of a node"
@property({type:String}) /**
* If true, only leafs (NOT folders) are selectable
*/
@property({type:Boolean})
leafOnly = false leafOnly = false

View File

@ -47,7 +47,6 @@ type Constructor<T = {}> = new (...args : any[]) => T;
export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidgetInterface & typeof LitElement, TreeSearchResult, TreeSearchResults>(Et2WidgetWithSelectMixin(LitElement)) export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidgetInterface & typeof LitElement, TreeSearchResult, TreeSearchResults>(Et2WidgetWithSelectMixin(LitElement))
{ {
static get styles() static get styles()
{ {
return [ return [
@ -65,8 +64,9 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
/** The component's help text. If you need to display HTML, use the `help-text` slot instead. */ /** The component's help text. If you need to display HTML, use the `help-text` slot instead. */
@property({attribute: 'help-text'}) helpText = ""; @property({attribute: 'help-text'}) helpText = "";
/** "JSON URL or menuaction to be called for nodes marked with child=1, but not having children, getSelectedNode() contains node-id" */
@property({type: String}) @property({type: String})
autoloading: string = "" //description: "JSON URL or menuaction to be called for nodes marked with child=1, but not having children, getSelectedNode() contains node-id" autoloading: string = "";
/** /**
* Indicates whether the dropdown is open. You can toggle this attribute to show and hide the tree, or you can * Indicates whether the dropdown is open. You can toggle this attribute to show and hide the tree, or you can
@ -80,6 +80,9 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
*/ */
@property({type: Object}) actions = {}; @property({type: Object}) actions = {};
/**
* If true, only leafs (NOT folders) are selectable
*/
@property() @property()
set leafOnly(_leafOnly: boolean) set leafOnly(_leafOnly: boolean)
{ {
@ -94,6 +97,10 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
} }
) )
} }
get leafOnly()
{
return this._tree?.leafOnly;
}
@state() currentTag: Et2Tag; @state() currentTag: Et2Tag;

View File

@ -297,7 +297,9 @@ export const SearchMixin = <T extends Constructor<Et2InputWidgetInterface &
*/ */
public searchMatch<DataType extends SearchResult>(search : string, searchOptions : Object, option : DataType) : boolean public searchMatch<DataType extends SearchResult>(search : string, searchOptions : Object, option : DataType) : boolean
{ {
if(!option || !option.value) if(!option || !option.value ||
// do NOT return folders, if leafOnly is set
this.leafOnly && typeof option.children !== 'undefined')
{ {
return false; return false;
} }