Skip to content

Commit d7b231b

Browse files
committed
Added easy-autocomplete widget (#11 - add easyautocomplete plugin for text editor)
1 parent cea3413 commit d7b231b

File tree

6 files changed

+271
-173
lines changed

6 files changed

+271
-173
lines changed

examples/jquery/index.html

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
<!DOCTYPE html>
22
<html>
3+
34
<head>
45
<title>Welcome to JQuery</title>
56
<script src="https://unpkg.com/jquery"></script>
67
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/css/bootstrap.min.css">
78

89
<!-- custom widgets -->
9-
<!-- select2 -->
10-
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/js/select2.min.js"></script>
11-
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/css/select2.min.css" rel="stylesheet" />
12-
<!-- select2 -->
10+
<!-- select2 -->
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/js/select2.min.js"></script>
12+
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/css/select2.min.css" rel="stylesheet" />
13+
<!-- select2 -->
1314
<!-- eo custom widgets-->
15+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/css/bootstrap.min.css">
16+
<link rel="stylesheet" href="./index.css">
17+
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
18+
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css" type="text/css" rel="stylesheet"
19+
/>
20+
21+
<!-- JS file -->
22+
<script src="https://unpkg.com/easy-autocomplete"></script>
23+
24+
<!-- CSS file -->
25+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/easy-autocomplete.css">
1426

1527
<!-- <script src="https://unpkg.com/survey-jquery"></script> TODO uncomment and remove the import below after the surveyjs release-->
16-
<script src="http://127.0.0.1:8080/packages/survey-jquery/survey.jquery.js"></script>
17-
28+
<script src="http://127.0.0.1:7777/packages/survey-jquery/survey.jquery.js"></script>
29+
1830

1931
<script src="../../package/surveyjs-widgets.js"></script>
2032
</head>
2133

2234
<body>
23-
<div id="surveyElement">
24-
</div>
25-
<script src="./index.js"></script>
35+
<div id="surveyElement">
36+
</div>
37+
<script src="./index.js"></script>
2638
</body>
27-
</html>
39+
40+
</html>

examples/jquery/index.js

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,55 @@
11
function init() {
2-
//$.material.init();
2+
//$.material.init();
33

4-
var json = { questions: [
5-
{ type: "dropdown", renderAs: "select2", choicesByUrl: { url: "https://restcountries.eu/rest/v1/all" }, name: "countries", title: "Please select the country you have arrived from:"}
6-
]};
4+
var json = {
5+
questions: [
6+
{
7+
type: "dropdown",
8+
renderAs: "select2",
9+
choicesByUrl: { url: "https://restcountries.eu/rest/v1/all" },
10+
name: "countries",
11+
title: "Please select the country you have arrived from:"
12+
},
13+
{
14+
name: "date",
15+
type: "datepicker",
16+
inputType: "date",
17+
title: "Your favorite date:",
18+
dateFormat: "mm/dd/yy",
19+
isRequired: true
20+
},
21+
{
22+
name: "autocomplete1",
23+
title: "Easy-autocomplete:",
24+
type: "text",
25+
choices: [
26+
"fontawesome-stars",
27+
"css-stars",
28+
"bars-pill",
29+
"bars-1to10",
30+
"bars-movie",
31+
"bars-square",
32+
"bars-reversed",
33+
"bars-horizontal",
34+
"bootstrap-stars",
35+
"fontawesome-stars-o"
36+
]
37+
}
38+
]
39+
};
740

8-
Survey.defaultBootstrapCss.navigationButton = "btn btn-primary";
9-
//Survey.Survey.cssType = "bootstrapmaterial";
10-
Survey.Survey.cssType = "bootstrap";
41+
Survey.defaultBootstrapCss.navigationButton = "btn btn-primary";
42+
//Survey.Survey.cssType = "bootstrapmaterial";
43+
Survey.Survey.cssType = "bootstrap";
1144

12-
var model = new Survey.Model(json);
13-
window.survey = model;
45+
var model = new Survey.Model(json);
46+
window.survey = model;
1447

15-
$("#surveyElement").Survey({
16-
model: survey
17-
});
48+
$("#surveyElement").Survey({
49+
model: survey
50+
});
1851
}
1952

20-
if(!window["%hammerhead%"]) {
21-
init();
53+
if (!window["%hammerhead%"]) {
54+
init();
2255
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"devDependencies": {
1111
"clean-webpack-plugin": "^0.1.17",
1212
"copy-webpack-plugin": "^4.1.1",
13+
"easy-autocomplete": "^1.3.5",
1314
"friendly-errors-webpack-plugin": "^1.6.1",
1415
"generate-json-webpack-plugin": "^0.2.2",
1516
"icheck": "^1.0.2",

src/easy-autocomplete.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
function init(Survey) {
2+
var widget = {
3+
name: "autocomplete",
4+
title: "Autocomplete",
5+
iconName: "icon-autocomplete",
6+
widgetIsLoaded: function() {
7+
return typeof $ === "function" && !!$.fn.easyAutocomplete;
8+
},
9+
defaultJSON: {},
10+
isFit: function(question) {
11+
return question.getType() === "text";
12+
},
13+
isDefaultRender: true,
14+
activatedByChanged: function(activatedBy) {
15+
if (Survey.JsonObject.metaData.findProperty("text", "choices") !== null) {
16+
return;
17+
}
18+
Survey.JsonObject.metaData.addProperty("text", {
19+
name: "choices:itemvalues",
20+
onGetValue: function(obj) {
21+
return ItemValue.getData(obj.choices);
22+
},
23+
onSetValue: function(obj, value) {
24+
obj.choices = value;
25+
}
26+
});
27+
},
28+
afterRender: function(question, el) {
29+
var $el = $(el).is("input") ? $(el) : $(el).find("input");
30+
var options = {
31+
data: question.choices,
32+
placeholder: question.placeholder
33+
};
34+
$el.easyAutocomplete(options);
35+
},
36+
willUnmount: function(question, el) {
37+
// var $el = $(el).find("input");
38+
// $el.autocomplete("destroy");
39+
}
40+
};
41+
42+
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "customtype");
43+
}
44+
45+
if (typeof Survey !== "undefined") {
46+
init(Survey);
47+
}
48+
49+
export default init;

src/surveyjs-widgets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export { default as select2tagbox } from "./select2-tagbox.js";
99
export { default as signaturepad } from "./signature_pad.js";
1010
export { default as sortablejs } from "./sortablejs.js";
1111
export { default as ckeditor } from "./ck-editor.js";
12+
export { default as autocomplete } from "./easy-autocomplete.js";

0 commit comments

Comments
 (0)