custom-metrosurvey-widgets
Version:
Custom widgets for the SurveyJS library
7 lines • 5.14 kB
JavaScript
/*!
* custom-metrosurvey-widgets - Widgets for the SurveyJS library v1.0.27
* Copyright (c) 2015-2022 Devsoft Baltic OÜ - http://surveyjs.io/
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("widgets/select2-tagbox",[],t):"object"==typeof exports?exports["widgets/select2-tagbox"]=t():e["widgets/select2-tagbox"]=t()}(window,(function(){return function(e){var t={};function n(a){if(t[a])return t[a].exports;var l=t[a]={i:a,l:!1,exports:{}};return e[a].call(l.exports,l,l.exports,n),l.l=!0,l.exports}return n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var l in e)n.d(a,l,function(t){return e[t]}.bind(null,l));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=11)}({11:function(e,t,n){"use strict";function a(e,t){e.SvgRegistry&&e.SvgRegistry.registerIconFromSvg("icon-tagbox",n(22),""),t=t||window.$;var a={name:"tagbox",title:"Tag box",iconName:"icon-tagbox",widgetIsLoaded:function(){return"function"==typeof t&&!!t.fn.select2},defaultJSON:{choices:["Item 1","Item 2","Item 3"]},htmlTemplate:"<div><select multiple='multiple' style='width: 100%;'></select><textarea></textarea></div>",isFit:function(e){return"tagbox"===e.getType()},activatedByChanged:function(t){e.JsonObject.metaData.addClass("tagbox",[{name:"hasOther:boolean",visible:!1},{name:"hasSelectAll:boolean",visible:!1},{name:"hasNone:boolean",visible:!1},{name:"otherText",visible:!1},{name:"selectAllText",visible:!1},{name:"noneText",visible:!1}],null,"checkbox"),e.JsonObject.metaData.addProperty("tagbox",{name:"select2Config",category:"general",default:null}),e.JsonObject.metaData.addProperty("tagbox",{name:"placeholder",category:"general",default:""}),e.JsonObject.metaData.addProperty("tagbox",{name:"allowAddNewTag:boolean",category:"general",default:!1})},fixStyles:function(e){e.parentElement.querySelector(".select2-search__field").style.border="none"},afterRender:function(e,n){var a=this,l=e.select2Config,o=l&&"string"==typeof l?JSON.parse(l):l,r=t(n).is("select")?t(n):t(n).find("select");a.willUnmount(e,n),o||(o={}),o.placeholder=e.placeholder,o.tags=e.allowAddNewTag,e.allowAddNewTag&&(e.keepIncorrectValues=!0),o.disabled=e.isReadOnly,o.theme="classic",e.maxSelectedChoices&&(o.maximumSelectionLength=e.maxSelectedChoices),r.select2(o);var c=t(n).find("textarea");e.survey&&e.survey.css&&e.survey.css.checkbox&&c.addClass(e.survey.css.checkbox.other),c.placeholder=e.otherPlaceHolder,c.bind("input propertychange",(function(){e.comment=c.val()}));var i=function(){c.val(e.comment),e.isOtherSelected?c.show():c.hide()};a.fixStyles(n);var s=function(){e.hasSelectAll&&e.isAllSelected?r.val([e.selectAllItemValue.value].concat(e.value)).trigger("change"):r.val(e.value).trigger("change"),a.fixStyles(n),i()},d=function(){r.select2().empty(),o.ajax||(o.data=e.visibleChoices.map((function(e){return{id:e.value,text:e.text}}))),r.select2(o),s()},u=function(t){return e.hasSelectAll&&t===e.selectAllItemValue.value};e._propertyValueChangedFnSelect2=function(){d()},c.prop("disabled",e.isReadOnly),e.readOnlyChangedCallback=function(){r.prop("disabled",e.isReadOnly),c.prop("disabled",e.isReadOnly)},e.registerFunctionOnPropertyValueChanged("visibleChoices",e._propertyValueChangedFnSelect2),e.valueChangedCallback=s,r.on("select2:select",(function(t){u(t.params.data.id)?e.selectAll():e.value=(e.value||[]).concat(t.params.data.id),i()})),r.on("select2:unselect",(function(t){const n=t.params.data.id;if(u(n))e.clearValue();else{const t=[].concat(e.renderedValue);if(Array.isArray(t))for(var a=0;a<t.length;a++)if(t[a]==n||t[a]&&t[a].toString()==n){t.splice(a,1),e.renderedValue=t;break}}i()})),d()},willUnmount:function(e,n){if(e._propertyValueChangedFnSelect2){var a=t(n).find("select");a.data("select2")&&a.off("select2:select").select2("destroy"),e.readOnlyChangedCallback=null,e.valueChangedCallback=null,e.unRegisterFunctionOnPropertyValueChanged("visibleChoices",e._propertyValueChangedFnSelect2),e._propertyValueChangedFnSelect2=void 0}},pdfQuestionType:"checkbox"};e.CustomWidgetCollection.Instance.addCustomWidget(a,"customtype")}n.r(t),"undefined"!=typeof Survey&&a(Survey,window.$),t.default=a},22:function(e,t){e.exports='<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><g><path d="M15,11H0V5h15V11z M1,10h13V6H1V10z"></path></g><rect x="2" y="7" width="4" height="2"></rect><rect x="7" y="7" width="4" height="2"></rect></svg>'}})}));
//# sourceMappingURL=select2-tagbox.min.js.map