Commit 7281efe5 authored by Evren Kutar's avatar Evren Kutar

custom search widget for typeahead

rref #5374
parent f61e0b51
...@@ -4,21 +4,8 @@ ...@@ -4,21 +4,8 @@
{{form.title}} {{form.title}}
</label> </label>
<!--<div class="form-group input-group">--> <input ng-if="form.widget!=='custom'"
<!--<span class="input-group-btn">--> type="text"
<!--<button class="btn btn-default dropdown-toggle" type="button"-->
<!--data-toggle="dropdown">-->
<!--<span class="caret"></span>-->
<!--</button>-->
<!--<ul class="dropdown-menu">-->
<!--<li class="text-center" ng-if="form.gettingTitleMap"><a><span class="loader"></span></a></li>-->
<!--<li ng-repeat="item in form.titleMap">-->
<!--<a ng-click="form.onDropdownSelect(item, form.name)">{{item-->
<!--.name}}</a>-->
<!--</li>-->
<!--</ul>-->
<!--</span>-->
<input type="text"
autocomplete="off" autocomplete="off"
ng-model="$$value$$" ng-model="$$value$$"
uib-typeahead="item as item.name for item in form.titleMap" uib-typeahead="item as item.name for item in form.titleMap"
...@@ -32,7 +19,23 @@ ...@@ -32,7 +19,23 @@
class="form-control {{form.fieldHtmlClass}}" class="form-control {{form.fieldHtmlClass}}"
schema-validate="form" schema-validate="form"
name="{{form.name}}"/> name="{{form.name}}"/>
<!--</div>-->
<input ng-if="form.widget==='custom'"
type="text"
autocomplete="off"
ng-model="$$value$$"
uib-typeahead="item as item.name for item in getTitleMap($viewValue)"
typeahead-wait-ms="500"
typeahead-loading="loadingTitleMap"
typeahead-on-select="form.onDropdownSelect($item, form.name)"
placeholder="{{form.title}}"
ng-model-options="form.ngModelOptions"
ng-disabled="form.readonly"
sf-changed="form"
class="form-control {{form.fieldHtmlClass}}"
schema-validate="form"
name="{{form.name}}"/>
<div ng-show="loadingTitleMap" class="loader"></div> <div ng-show="loadingTitleMap" class="loader"></div>
<div class="help-block" sf-message="form.description"></div> <div class="help-block" sf-message="form.description"></div>
</div> </div>
\ No newline at end of file
...@@ -773,6 +773,35 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -773,6 +773,35 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
} }
}; };
v.type = 'string'; v.type = 'string';
},
custom: function (scope, v, k) {
scope.form[scope.form.indexOf(k)] = {
type: "template",
title: v.title,
getTitleMap: function (viewValue) {
// v.view is where that value will looked up
var searchData = {
"url": v.wf,
"wf": v.wf,
"view": v.view,
"query": viewValue
};
generator.get_list(searchData).then(function (res) {
// response must be in titleMap format
return res;
});
},
templateUrl: "shared/templates/typeahead.html",
name: k,
key: k,
onDropdownSelect: function (item, inputname) {
scope.model[k] = item.value;
$timeout(function () {
document.querySelector('input[name=' + inputname + ']').value = item.name;
});
}
};
v.type = 'string';
} }
}, },
text_general: { text_general: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment