Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jqueryui autocomplete enhancement #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ var contacts = [
{ label: "Zimbabwe", id: "ZW" },
],
},
[
{id:"Fruits", type:"input-autocomplete", label:"fruit",
api: "{{url('api/fruit')}}"
}
]
];

var sampleConditions = [
Expand Down
43 changes: 39 additions & 4 deletions js/structured-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
list: "list",
listOpts: "list-options",
listDropdown: "list-dropdown",
inputAutoc: "input-autocomplete"
},
// - i18n strings (to translate in other languages)
i18n = {
Expand Down Expand Up @@ -191,7 +192,7 @@
that._field = that._getFieldById(fieldID);
var fType = (that._type = that._field.type);
that._setEditorOperator();
if (fType === fTypes.bool || fType.startsWith("list")) {
if (fType === fTypes.bool || fType.startsWith("list") || fType.startsWith('input')) {
that._setEditorValue();
}
} else {
Expand All @@ -213,7 +214,7 @@
var fType = that._type,
value = $(this).val(),
valid =
value !== "" || fType === fTypes.bool || fType.startsWith("list");
value !== "" || fType === fTypes.bool || fType.startsWith("list") || fType.startsWith('input');
if (fType == fTypes.number) {
valid = valid && !isNaN(value);
} else if (
Expand Down Expand Up @@ -388,7 +389,7 @@
this._bDel.show();
if (!this._fList) {
this._fList =
'<select id="field">' +
'<select id="field" class="selectize">' +
EvoUI.optNull +
this.options.fields.map(function (f) {
return EvoUI.inputOption(f.id, f.label);
Expand Down Expand Up @@ -423,6 +424,7 @@
break;
case fTypes.listOpts:
case fTypes.listDropdown:
case fTypes.inputAutoc:
case fTypes.bool:
//h.push(i18n.sEqual);
h += EvoUI.inputHidden("operator", evoAPI.sEqual);
Expand Down Expand Up @@ -537,6 +539,12 @@
})
.join("") +
"</select>";
break;
case fTypes.inputAutoc:
console.log('autocomplete input');
var autoCompleteObj = '<input id="value" type="text" class="basicAutoComplete" data-url="'+fld.api+'" autocomplete="off">';
h +=
autoCompleteObj;
break;
case fTypes.date:
case fTypes.time:
Expand Down Expand Up @@ -564,6 +572,24 @@
.find("#value,#value2")
.datepicker({ dateFormat: this.options.dateFormat });
}
if (fType == fTypes.inputAutoc) {
editor
.find("#value")
.each(function(){
var $this = $(this);
var url = $(this).data('url');
$this.autocomplete({
source: function (request, response) {
jQuery.get(url, {
s: request.term
}, function (data) {
response(data);
});
},
minLength: 3
});
});
}
}
if (v) {
var $value = editor.find("#value");
Expand Down Expand Up @@ -657,7 +683,16 @@
fv.label = i18n.sIsNull;
}
fv.value = v.val();
} else {
}
else if (this._type == fTypes.inputAutoc) {
op.label = i18n.sIs;
op.value = evoAPI.sEqual;
var val = v.val()
console.log(val);
fv.label = val;
fv.value = val;
}
else {
var o = e.find("#operator"),
opVal = o.val();
op.label = o.find("option:selected").text();
Expand Down