surveyjs-widgets
Version:
Custom widgets for the SurveyJS library
3 lines • 4.58 kB
JavaScript
/*! For license information please see select2-tagbox.min.js.LICENSE.txt */
!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()}(self,(()=>(()=>{var e={14:e=>{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>'}},t={};function l(a){var n=t[a];if(void 0!==n)return n.exports;var r=t[a]={exports:{}};return e[a](r,r.exports,l),r.exports}l.d=(e,t)=>{for(var a in t)l.o(t,a)&&!l.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),l.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{"use strict";function e(e,t){const a="icon-tagbox",n="tagbox";e.SvgRegistry&&e.SvgRegistry.registerIconFromSvg(a,l(14),""),t=t||window.$;var r={name:n,title:"Tag box",iconName:a,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 e.getType()===n},activatedByChanged:function(t){if(e.Serializer.findClass(n))return;e.Serializer.addClass(n,[{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");let l=e.ElementFactory.Instance.registerCustomQuestion;l&&l(n),e.Serializer.addProperty(n,{name:"select2Config",category:"general",default:null}),e.Serializer.addProperty(n,{name:"placeholder",category:"general",default:""}),e.Serializer.addProperty(n,{name:"allowAddNewTag:boolean",category:"general",default:!1})},fixStyles:function(e){e.parentElement.querySelector(".select2-search__field").style.border="none"},afterRender:function(e,l){var a=this,n=e.select2Config,r=n&&"string"==typeof n?JSON.parse(n):n,o=t(l).is("select")?t(l):t(l).find("select");a.willUnmount(e,l),r||(r={}),r.placeholder=e.placeholder,r.tags=e.allowAddNewTag,e.allowAddNewTag&&(e.keepIncorrectValues=!0),r.disabled=e.isReadOnly,r.theme="classic",e.maxSelectedChoices&&(r.maximumSelectionLength=e.maxSelectedChoices),o.select2(r);var i=t(l).find("textarea");e.survey&&e.survey.css&&e.survey.css.checkbox&&i.addClass(e.survey.css.checkbox.other),i.placeholder=e.otherPlaceHolder,i.bind("input propertychange",(function(){e.comment=i.val()}));var c=function(){i.val(e.comment),e.isOtherSelected?i.show():i.hide()};a.fixStyles(l);var s=function(){e.hasSelectAll&&e.isAllSelected?o.val([e.selectAllItemValue.value].concat(e.value)).trigger("change"):o.val(e.value).trigger("change"),a.fixStyles(l),c()},d=function(){o.select2().empty(),r.ajax||(r.data=e.visibleChoices.map((function(e){return{id:e.value,text:e.text}}))),o.select2(r),s()},u=function(t){return e.hasSelectAll&&t===e.selectAllItemValue.value};e._propertyValueChangedFnSelect2=function(){d()},i.prop("disabled",e.isReadOnly),e.readOnlyChangedCallback=function(){o.prop("disabled",e.isReadOnly),i.prop("disabled",e.isReadOnly)},e.registerFunctionOnPropertyValueChanged("visibleChoices",e._propertyValueChangedFnSelect2),e.valueChangedCallback=s,o.on("select2:select",(function(t){u(t.params.data.id)?e.selectAll():e.value=(e.value||[]).concat(t.params.data.id),c()})),o.on("select2:unselect",(function(t){const l=t.params.data.id;if(u(l))e.clearValue();else{const t=[].concat(e.renderedValue);if(Array.isArray(t))for(var a=0;a<t.length;a++)if(t[a]==l||t[a]&&t[a].toString()==l){t.splice(a,1),e.renderedValue=t;break}}c()})),d()},willUnmount:function(e,l){if(e._propertyValueChangedFnSelect2){var a=t(l).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(r,"customtype")}l.r(a),l.d(a,{default:()=>t}),"undefined"!=typeof Survey&&e(Survey,window.jQuery);const t=e})(),a})()));
//# sourceMappingURL=select2-tagbox.min.js.map