surveyjs-widgets
Version:
Custom widgets for the SurveyJS library
3 lines • 4.01 kB
JavaScript
/*! For license information please see select2.min.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("widgets/select2",[],t):"object"==typeof exports?exports["widgets/select2"]=t():e["widgets/select2"]=t()}(self,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e,t){t=t||window.$;const n="select2";var a={activatedBy:"property",name:n,widgetIsLoaded:function(){return"function"==typeof t&&!!t.fn.select2},isFit:function(e){return"property"==a.activatedBy?e.renderAs===n&&"dropdown"===e.getType():"type"==a.activatedBy?"dropdown"===e.getType():"customtype"==a.activatedBy&&e.getType()===n},activatedByChanged:function(t){if(this.widgetIsLoaded()&&(a.activatedBy=t,e.Serializer.removeProperty("dropdown","renderAs"),"property"==t&&(e.Serializer.addProperty("dropdown",{name:"renderAs",category:"general",default:"default",choices:[n,"default"]}),e.Serializer.addProperty("dropdown",{dependsOn:"renderAs",category:"general",name:"select2Config",visibleIf:function(e){return e.renderAs==n}})),"customtype"==t)){if(e.Serializer.findClass(n))return;e.Serializer.addClass(n,[],null,"dropdown");let t=e.ElementFactory.Instance.registerCustomQuestion;t&&t(n),e.Serializer.addProperty(n,{name:"select2Config",category:"general",default:null})}},htmlTemplate:"<div><select style='width: 100%;'></select><textarea></textarea></div>",afterRender:function(e,n){var a=e.select2Config,l=a&&"string"==typeof a?JSON.parse(a):a;l||(l={});var o=t(n).is("select")?t(n):t(n).find("select"),i=t(n).find("textarea");i.addClass(e.cssClasses.other),i.bind("input propertychange",(function(){d||(e.comment=i.val())}));var r=function(){i.val(e.comment),e.isOtherSelected?i.show():i.hide()},d=!1,s=function(){if(!d){if(d=!0,o.find('option[value="'+(e.value||"")+'"]').length)o.val(e.value).trigger("change");else if(null!==e.value&&void 0!==e.value&&!e.isOtherSelected){var t=new Option(e.value,e.value,!0,!0);o.append(t).trigger("change")}r(),d=!1}},c=function(){if(o.select2().empty(),!l.placeholder&&e.showOptionsCaption&&(l.placeholder=e.optionsCaption,l.allowClear=!0),l.theme||(l.theme="classic"),l.disabled=e.isReadOnly,l.ajax)o.select2(l),e.keepIncorrectValues=!0;else{var t=[];(l.placeholder||e.showOptionsCaption)&&t.push({id:"",text:""}),l.data=t.concat(e.visibleChoices.map((function(e){return{id:e.value,text:e.text}}))),e.clearIncorrectValues(),o.select2(l)}n.querySelector(".select2")&&(n.querySelector(".select2").style.width="100%"),n.nextElementSibling&&(n.nextElementSibling.style.marginBottom="1px"),s()};i.prop("disabled",e.isReadOnly),e.readOnlyChangedCallback=function(){o.prop("disabled",e.isReadOnly),i.prop("disabled",e.isReadOnly)},e.registerFunctionOnPropertyValueChanged("visibleChoices",(function(){c()})),c(),o.on("change",(function(t){setTimeout((function(){e.renderedValue=t.target.value,r()}),1)})),o.on("select2:select",(function(t){setTimeout((function(){e.renderedValue=t.target.value,r()}),1)})),o.on("select2:opening",(function(e){t(this).data("unselecting")&&(t(this).removeData("unselecting"),e.preventDefault())})),o.on("select2:unselecting",(function(n){t(this).data("unselecting",!0),setTimeout((function(){e.renderedValue=null,r()}),1)})),e.valueChangedCallback=s,s()},willUnmount:function(e,a){e.readOnlyChangedCallback=null,e.valueChangedCallback=null;var l=t(a).find("select");l.data(n)&&l.off("select2:select").off("select2:unselecting").off("select2:opening").select2("destroy")}};e.CustomWidgetCollection.Instance.addCustomWidget(a)}e.r(t),e.d(t,{default:()=>a}),"undefined"!=typeof Survey&&n(Survey,window.jQuery);const a=n;return t})()));
//# sourceMappingURL=select2.min.js.map