Spaces:
No application file
No application file
File size: 2,756 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
diff --git a/node_modules/chosen-js/chosen.jquery.js b/node_modules/chosen-js/chosen.jquery.js
index dbc3a25..3a1e473 100644
--- a/node_modules/chosen-js/chosen.jquery.js
+++ b/node_modules/chosen-js/chosen.jquery.js
@@ -382,15 +382,38 @@
}
}
this.result_clear_highlight();
- if (results < 1 && query.length) {
+
+ // Mautic hack to allow adding new options - start
+
+ var resultsCount = this.results_data.length,
+ selectedCount = 0;
+
+ for (_i = 0, _len = this.results_data.length; _i < _len; _i++) {
+ if (!this.results_data[_i].group && this.results_data[_i].selected) {
+ selectedCount++;
+ }
+ }
+
+ if ((results < 1 || (resultsCount > 0 && resultsCount === selectedCount && $(this.form_field).data('allow-add'))) && query.length) {
this.update_results_content("");
return this.no_results(query);
} else {
this.update_results_content(this.results_option_build());
- if (!(options != null ? options.skip_highlight : void 0)) {
- return this.winnow_results_set_highlight();
- }
+ return this.winnow_results_set_highlight();
}
+
+ // Mautic hack to allow adding new options - end
+
+ // Original:
+ // if (results < 1 && query.length) {
+ // this.update_results_content("");
+ // return this.no_results(query);
+ // } else {
+ // this.update_results_content(this.results_option_build());
+ // if (!(options != null ? options.skip_highlight : void 0)) {
+ // return this.winnow_results_set_highlight();
+ // }
+ // }
};
AbstractChosen.prototype.get_search_regex = function(escaped_search_string) {
@@ -456,6 +479,23 @@
case 13:
if (this.results_showing) {
evt.preventDefault();
+
+ // Mautic hack to allow adding new entries if applicable - start
+ if (!$(this.form_field).data('allow-add') || !this.is_multiple || this.result_highlight) {
+ return this.result_select(evt);
+ }
+
+ var newTag = $(evt.target).val();
+
+ if ($(this.form_field).find('option').filter(function(){ return $(this).text() === newTag}).length === 0) {
+ $(this.form_field).append('<option>' + newTag + '</option>');
+ $(this.form_field).trigger('chosen:updated');
+ this.result_highlight = this.search_results.find('li.active-result').last();
+
+ return this.result_select(evt);
+ }
+ // Mautic hack to allow adding new entries if applicable - end
+
}
break;
case 27:
@@ -1345,3 +1385,4 @@
})(AbstractChosen);
}).call(this);
+
|