UNPKG

scrivito-neoletter-form-widgets

Version:
1 lines 2.18 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("scrivito")):"function"==typeof define&&define.amd?define(["scrivito"],t):"object"==typeof exports?exports["scrivito-form-widgets"]=t(require("scrivito")):e["scrivito-form-widgets"]=t(e.scrivito)}(this,(e=>(()=>{"use strict";var t={2311:t=>{t.exports=e}},o={};function r(e){var i=o[e];if(void 0!==i)return i.exports;var n=o[e]={exports:{}};return t[e](n,n.exports,r),n.exports}r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};r.r(i),r.d(i,{customFieldNameValidation:()=>l,getFormContainer:()=>s,insideFormContainerValidation:()=>a});var n=r(2311);function s(e){let t=e.container();for(;t instanceof n.Widget;){const e=t.objClass();if("FormStepContainerWidget"===e||"FormContainerWidget"===e)return t;t=t.container()}return null}function a(e){return s(e)?"":"Needs to be inside a Neoletter form."}function c(e){return!e.attributeDefinitions().type||"custom"===e.get("type")}function u(e){return c(e)?e.get("customFieldName"):"urlParam"==e.get("type")?e.get("urlParameterFieldName")||"":e.get("type")}const l=["customFieldName",(e,{widget:t})=>c(t)?((e,t)=>e.startsWith("custom_")?e.length<=7?"Specify the custom field's name.":null===e.match(/^[A-Za-z_][A-Za-z0-9_]*$/)?'Custom field names may consist of the following characters: "a-z", "A-Z", "0-9", "_".':e.length>50?`Custom field names may be up to 50 characters long. This name is ${e.length} characters long.`:function(e){const t=u(e);if(null==(o=t)||(o instanceof Map||o instanceof Set?0===o.size:[Object,Array].includes((o||{}).constructor)&&!Object.entries(o||{}).length))return!0;var o;const r=s(e);return!r||!r.widgets().find((o=>u(o)===t&&o.id()!==e.id()))}(t)?"":"Specify a unique custom field name. There is at least one other element with the same custom field name.":'Custom field names must start with "custom_".')(e,t):""];return i})()));