Skip to content

Commit fbf7bfc

Browse files
committed
Basic support for mdAutocomplete
I have added a working example, but it still needs options and filters to be added.
1 parent 182a2ab commit fbf7bfc

6 files changed

+262
-151
lines changed

examples/data/autocomplete.json

+23-52
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,38 @@
11
{
22
"schema": {
33
"type": "object",
4-
"title": "Comment",
5-
"required": ["comments"],
4+
"title": "Arnold Schwarzenegger",
65
"properties": {
7-
"comments": {
8-
"type": "array",
9-
"maxItems": 2,
10-
"items": {
11-
"type": "object",
12-
"properties": {
13-
"name": {
14-
"title": "Name",
15-
"type": "string"
16-
},
17-
"email": {
18-
"title": "Email",
19-
"type": "string",
20-
"pattern": "^\\S+@\\S+$",
21-
"description": "Email will be used for evil."
22-
},
23-
"spam": {
24-
"title": "Spam",
25-
"type": "boolean",
26-
"default": true
27-
},
28-
"comment": {
29-
"title": "Comment",
30-
"type": "string",
31-
"maxLength": 20,
32-
"validationMessage": "Don't be greedy!"
33-
}
34-
},
35-
"required": ["name","comment"]
36-
}
6+
"first": {
7+
"title": "What is your favourite Schwarzenegger movie?",
8+
"type": "string"
9+
},
10+
"second": {
11+
"title": "What is your favourite Schwarzenegger movie?",
12+
"type": "string"
3713
}
3814
}
3915
},
4016
"form": [
17+
{
18+
"key": "first",
19+
"type": "autocomplete",
20+
"optionFilter": "querySearch"
21+
},
4122
{
4223
"type": "help",
43-
"helpvalue": "<h4>Array Example</h4><p>Try adding a couple of forms, reorder by drag'n'drop.</p>"
24+
"helpvalue": "I only need at least 1 character"
4425
},
4526
{
46-
"key": "comments",
47-
"add": "New",
48-
"style": {
49-
"add": "btn-success"
50-
},
51-
"items": [
52-
"comments[].name",
53-
"comments[].email",
54-
{
55-
"key": "comments[].spam",
56-
"type": "checkbox",
57-
"title": "Yes I want spam.",
58-
"condition": "model.comments[arrayIndex].email"
59-
},
60-
{
61-
"key": "comments[].comment",
62-
"type": "textarea"
63-
}
64-
]
27+
"title": "What is your second favourite Schwarzenegger movie?",
28+
"key": "second",
29+
"type": "autocomplete",
30+
"optionFilter": "querySearch",
31+
"minLength": 4
32+
},
33+
{
34+
"type": "help",
35+
"helpvalue": "I need at least 4 characters"
6536
},
6637
{
6738
"type": "submit",

examples/material-example.html

+103-11
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,11 @@ <h2>Material Design</h2>
168168
<div layout="column" flex="45">
169169
<h3>The Generated Form</h3>
170170

171-
<form name="ngform" sf-model="modelData" sf-form="form" sf-schema="schema" ng-submit="submitForm(ngform,modelData)"></form>
172-
<!--
173171
<form name="ngform"
174172
sf-model="modelData"
175173
sf-form="form"
176174
sf-schema="schema"
177-
ng-submit="submitForm(ngform,modelData)">
178-
</form>
179-
-->
175+
ng-submit="submitForm(ngform,modelData)"></form>
180176

181177
<div ng-show="ngform.$valid"><em>Form is valid</em></div>
182178
<div ng-show="ngform.$invalid"><em>Form is not valid</em></div>
@@ -245,10 +241,6 @@ <h3>Schema</h3>
245241
<script type="text/javascript" src="../bower_components/angular-ui-ace/ui-ace.js"></script>
246242
<script type="text/javascript" src="../bower_components/objectpath/lib/ObjectPath.js"></script>
247243
<!--
248-
<script type="text/javascript" src="../bower_components/pickadate/lib/picker.js"></script>
249-
<script type="text/javascript" src="../bower_components/pickadate/lib/picker.date.js"></script>
250-
<script type="text/javascript" src="../bower_components/pickadate/lib/translations/nl_NL.js"></script>
251-
252244
<script type="text/javascript" src="../bower_components/spectrum/spectrum.js"></script>
253245
<script type="text/javascript" src="../bower_components/spectrum/i18n/jquery.spectrum-sv.js"></script>
254246
<script type="text/javascript" src="../bower_components/angular-spectrum-colorpicker/dist/angular-spectrum-colorpicker.min.js"></script>
@@ -284,10 +276,10 @@ <h3>Schema</h3>
284276
});
285277

286278

287-
app.controller('TestCtrl', function($scope, $http, $location) {
279+
app.controller('TestCtrl', function($scope, $http, $location, $timeout, $q) {
288280

289281
$scope.tests = [
290-
/*{ name: "Autocomplete", data: 'data/autocomplete.json' },*/
282+
{ name: "Autocomplete", data: 'data/autocomplete.json' },
291283
{ name: "Simple", data: 'data/simple.json' },
292284
{ name: "Basic JSON Schema Type", data: 'data/types.json' },
293285
{ name: "TitleMap Examples", data: 'data/titlemaps.json' },
@@ -300,6 +292,106 @@ <h3>Schema</h3>
300292
{ name: "Hack: Conditional required", data: 'data/conditional-required.json' },
301293
];
302294

295+
/////////////////////////////////////////////////////////////////////////
296+
//// Autocomplete code //////////////////////////////////////////////////
297+
$scope.arnieFlix = loadFlix();
298+
$scope.searchText = null;
299+
$scope.simulateQuery = false;
300+
$scope.querySearch = querySearch;
301+
$scope.info = function (t) {
302+
console.info(t);
303+
};
304+
/**
305+
* Search for arnieFlix... use $timeout to simulate
306+
* remote dataservice call.
307+
*/
308+
function querySearch (query) {
309+
var results = query ? $scope.arnieFlix.filter( createFilterFor(query) ) : $scope.arnieFlix,
310+
deferred;
311+
if ($scope.simulateQuery) {
312+
deferred = $q.defer();
313+
$timeout(function () { deferred.resolve( results ); }, Math.random() * 1000, false);
314+
return deferred.promise;
315+
} else {
316+
return results;
317+
}
318+
};
319+
320+
/**
321+
* Create filter function for a query string
322+
*/
323+
function createFilterFor(query) {
324+
var lowercaseQuery = angular.lowercase(query);
325+
return function filterFn(item) {
326+
return (item.value.indexOf(lowercaseQuery) === 0);
327+
};
328+
};
329+
330+
function loadFlix() {
331+
var films = [
332+
{ "year": undefined, "title": "The Legend of Conan" },
333+
{ "year": undefined, "title": "Triplets" },
334+
{ "year": 2015, "title": "Terminator Genisys" },
335+
{ "year": 2015, "title": "Maggie" },
336+
{ "year": 2014, "title": "The Expendables 3" },
337+
{ "year": 2014, "title": "Sabotage" },
338+
{ "year": 2013, "title": "Escape Plan" },
339+
{ "year": 2013, "title": "The Last Stand" },
340+
{ "year": 2012, "title": "The Expendables 2" },
341+
{ "year": 2010, "title": "The Expendables" },
342+
{ "year": 2005, "title": "The Kid & I" },
343+
{ "year": 2004, "title": "Around the World in 80 Days" },
344+
{ "year": 2003, "title": "Welcome to the Jungle" },
345+
{ "year": 2003, "title": "Terminator 3: Rise of the Machines" },
346+
{ "year": 2002, "title": "Collateral Damage" },
347+
{ "year": 2000, "title": "The 6th Day" },
348+
{ "year": 1999, "title": "End of Days" },
349+
{ "year": 1997, "title": "Batman & Robin" },
350+
{ "year": 1996, "title": "Jingle All the Way" },
351+
{ "year": 1996, "title": "Eraser" },
352+
{ "year": 1994, "title": "Junior" },
353+
{ "year": 1994, "title": "True Lies" },
354+
{ "year": 1993, "title": "Last Action Hero" },
355+
{ "year": 1993, "title": "Dave" },
356+
{ "year": 1991, "title": "Terminator 2: Judgment Day" },
357+
{ "year": 1990, "title": "Kindergarten Cop" },
358+
{ "year": 1990, "title": "Total Recall" },
359+
{ "year": 1988, "title": "Twins" },
360+
{ "year": 1988, "title": "Red Heat" },
361+
{ "year": 1987, "title": "The Running Man" },
362+
{ "year": 1987, "title": "Predator" },
363+
{ "year": 1986, "title": "Raw Deal" },
364+
{ "year": 1985, "title": "Commando" },
365+
{ "year": 1985, "title": "Red Sonja" },
366+
{ "year": 1984, "title": "The Terminator" },
367+
{ "year": 1984, "title": "Conan the Destroyer" },
368+
{ "year": 1982, "title": "Conan the Barbarian" },
369+
{ "year": 1980, "title": "The Jayne Mansfield Story" },
370+
{ "year": 1979, "title": "Scavenger Hunt" },
371+
{ "year": 1979, "title": "The Villain" },
372+
{ "year": 1976, "title": "Stay Hungry" },
373+
{ "year": 1974, "title": "Happy Anniversary and Goodbye" },
374+
{ "year": 1973, "title": "The Long Goodbye" },
375+
{ "year": 1969, "title": "Hercules in New York" },
376+
{ "year": 1969, "title": "Hercules" }
377+
];
378+
return films.map( function (film) {
379+
film.name = film.title;
380+
film.value = film.title.toLowerCase();
381+
return film;
382+
});
383+
};
384+
385+
// $scope.autocompleteTmpl = `
386+
// <span class="item-year">
387+
// <span> {{item.year}} </span>
388+
// </span>
389+
// <span class="item-title">
390+
// <strong>{{item.title}}</strong>
391+
// </span>`;
392+
//// Autocomplete code end //////////////////////////////////////////////
393+
/////////////////////////////////////////////////////////////////////////
394+
303395
$scope.navbarMode = 'default';
304396
//$scope.hasFlash = swfobject.hasFlashPlayerVersion('9');
305397

0 commit comments

Comments
 (0)