Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Added searchMethod
Browse files Browse the repository at this point in the history
You can now choose between searching with contains or starts-with.
  • Loading branch information
JelleDekker committed Sep 2, 2019
1 parent 18f3e85 commit dc17715
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/ComboSelector/ComboSelector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@
<description>Specify a microflow to execute on change of the attribute. (optional)</description>
<returnType type="Void"/>
</property>
<property key="searchMethod" type="enumeration" defaultValue="contains" required="true">
<caption>Search method</caption>
<category>Behavior</category>
<description>Base the search on contain or match with the start of the item.</description>
<enumerationValues>
<enumerationValue key="contains">Contains</enumerationValue>
<enumerationValue key="startswith">Starts with</enumerationValue>
</enumerationValues>
</property>
<property key="autoComplete" type="boolean" defaultValue="false">
<caption>Autocomplete</caption>
<category>Behavior</category>
Expand Down
5 changes: 4 additions & 1 deletion src/ComboSelector/lib/XpathStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ define([
associationDisplay: "",
XpathDeferred: "",
data: "",
searchMethod: "",

constructor: function (options) {
this.id = options.caller + '.XpathStore';
this.dataSourceXpath = options.dataSourceXpath;
this.dataSourceXpathLimit = options.dataSourceXpathLimit;;
this.sortParams = options.sortParams;
this.associationDisplay = options.associationDisplay;
this.searchMethod = options.searchMethod;
logger.debug(this.id + ".constructor");
},
query: function (query, options) {
Expand All @@ -32,7 +34,8 @@ define([
if (query.name) {
var
searchString = query.name.toString().replace(/\'/g, '&#39;').replace(/\"/g, '&#34;'),
xpathQuery = this.dataSourceXpath + "[contains(" + this.associationDisplay + ", '" + searchString + "')]";
xpathQuery = this.dataSourceXpath + "[" + this.searchMethod + "(" + this.associationDisplay + ", '" + searchString + "')]";
console.log("xpathQuery: " + xpathQuery);
mx.data.get({
xpath: xpathQuery,
filter: {
Expand Down
11 changes: 10 additions & 1 deletion src/ComboSelector/widget/ComboSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ define([
dataSourceXpathSortOrder: "",
dataSourceXpathExecution: "",
reloadOnRefresh: "",
searchMethod: "",


// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
Expand All @@ -79,6 +80,7 @@ define([
_association: null,
_entity: null,
_sortParams: null,
_searchMethodWidget: null,

// dojo.declare.constructor is called to construct the widget instance. Implement to initialize non-primitive properties.
constructor: function () {
Expand Down Expand Up @@ -107,6 +109,12 @@ define([
dojoClass.add(this.inputWrapper, "col-sm-" + (12 - this.labelWidth));
}

if (this.dataSourceSelection == "dataSourceMicroflow" || this.dataSourceXpathExecution == "widget"){
this._searchMethodWidget = (this.searchMethod == 'contains' ? "*${0}*" : "${0}*");
} else {
this._searchMethodWidget = (this.searchMethod == 'contains' ? "contains" : "starts-with");
}

this._association = this.associationEntity.split("/")[0];
this._entity = this.associationEntity.split("/")[1];

Expand Down Expand Up @@ -172,6 +180,7 @@ define([
dataSourceXpathLimit: this.dataSourceXpathLimit,
sortParams: this._sortParams,
associationDisplay: this.associationDisplay,
searchMethod: this._searchMethodWidget
});
this._buildComboBox();
} else if (this.dataSourceSelection == "dataSourceXpath" && this.dataSourceXpathExecution == "widget") {
Expand Down Expand Up @@ -218,7 +227,7 @@ define([
if (!this._comboBox) {
this._comboBox = new dojoComboBox({
store: this._comboBoxStore,
queryExpr: (this.dataSourceSelection == "dataSourceXpath" && this.dataSourceXpathExecution == "xpath" ? "${0}" : "*${0}*"),
queryExpr: (this.dataSourceSelection == "dataSourceXpath" && this.dataSourceXpathExecution == "xpath" ? "${0}" : this._searchMethodWidget),
searchAttr: "name",
autoComplete: this.autoComplete,
searchDelay: this.searchDelay
Expand Down
2 changes: 1 addition & 1 deletion src/package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="ComboSelector" version="1.2.3" xmlns="http://www.mendix.com/clientModule/1.0/">
<clientModule name="ComboSelector" version="1.3.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="ComboSelector/ComboSelector.xml" />
</widgetFiles>
Expand Down
Binary file modified test/widgets/ComboSelector.mpk
Binary file not shown.

0 comments on commit dc17715

Please sign in to comment.