[ * priority => 'choose one of the priority status code', * filename => 'fileName', * scriptTyp => 'script' or 'init' or 'custom' by default script * source => 'filePath' or 'url' or 'cdn' or className or customClassName by scriptTyp && by default it will be 'filePath'=> 'assets/js/fileName.js'', * fk => 'field key' * field => 'field object' * ] * final priority helper js common js custom field script js init for custom field js inti for CDN field js validation js confirmation js conditional js submit js custom js */ $initSource = '\\BitCode\\BitForm\\Admin\\Form\\InitJs\\'; $customSource = '\\BitCode\\BitForm\\Admin\\Form\\ExtraFieldJS\\'; return [ 'helperScript' => [ ['priority' => 101, 'filename' => 'bfSelect.min.js'], ['priority' => 101, 'filename' => 'bfReset.min.js'], ['priority' => 101, 'filename' => 'setBFMsg.min.js'], ['priority' => 101, 'filename' => 'scrollToFld.min.js'], ['priority' => 101, 'filename' => 'bfValidationErrMsg.min.js'], ['priority' => 101, 'filename' => 'setHiddenFld.min.js'], ['priority' => 101, 'filename' => 'submit-form.min.js'], ['priority' => 101, 'filename' => 'setStyleProperty.min.js'] ], 'country' => [ ['priority' => 101, 'filename' => 'observeElm.min.js'], ['priority' => 201, 'filename' => 'bit-virtualized-list.min.js'], ['priority' => 301, 'filename' => 'bit-country-field.min.js'], ['priority' => 501, 'filename' => 'Country', 'scriptTyp' => 'init', 'source' => $initSource], ['priority' => 201, 'filename' => 'customFieldsReset.min.js'], ['priority' => 101, 'filename' => 'observeElm.min.js'], ], 'currency' => [ ['priority' => 101, 'filename' => 'observeElm.min.js'], ['priority' => 201, 'filename' => 'bit-virtualized-list.min.js'], ['priority' => 301, 'filename' => 'bit-currency-field.min.js'], ['priority' => 501, 'filename' => 'Currency', 'scriptTyp' => 'init', 'source' => $initSource], ['priority' => 201, 'filename' => 'customFieldsReset.min.js'], ['priority' => 101, 'filename' => 'observeElm.min.js'], ], 'select' => [ ['priority' => 101, 'filename' => 'observeElm.min.js'], ['priority' => 301, 'filename' => 'bit-dropdown-field.min.js'], ['priority' => 501, 'filename' => 'Select', 'scriptTyp' => 'init', 'source' => $initSource], ['priority' => 201, 'filename' => 'customFieldsReset.min.js'], ['priority' => 101, 'filename' => 'observeElm.min.js'], ], 'advanced-file-up' => [ ['priority' => 101, 'filename' => 'observeElm.min.js'], ['priority' => 202, 'filename' => 'bit-filepond.min.js'], ['priority' => 301, 'filename' => 'bit-advance-file-upload-field.min.js'], ['priority' => 501, 'filename' => 'AdvancedFileUpload', 'scriptTyp' => 'init', 'source' => $initSource], ['priority' => 101, 'filename' => 'advancedFileHandle.min.js'], ['priority' => 201, 'filename' => 'customFieldsReset.min.js'], ], 'file-up' => [ ['priority' => 301, 'filename' => 'bit-file-up-field.min.js'], ['priority' => 501, 'filename' => 'FileUpload', 'scriptTyp' => 'init', 'source' => $initSource], ['priority' => 201, 'filename' => 'customFieldsReset.min.js'], ], 'phone-number' => [ ['priority' => 101, 'filename' => 'observeElm.min.js'], ['priority' => 201, 'filename' => 'bit-virtualized-list.min.js'], ['priority' => 301, 'filename' => 'bit-phone-number-field.min.js'], ['priority' => 501, 'filename' => 'PhoneNumber', 'scriptTyp' => 'init', 'source' => $initSource], ['priority' => 201, 'filename' => 'customFieldsReset.min.js'], ['priority' => 101, 'filename' => 'observeElm.min.js'], ], 'paypal' => [ ['priority' => 101, 'filename' => 'paymentSubmitResponse.min.js'], ['priority' => 301, 'filename' => 'bit-paypal-field.min.js'], ['priority' => 601, 'filename' => 'Paypal', 'scriptTyp' => 'init', 'source' => $initSource], ], 'razorpay' => [ ['priority' => 101, 'filename' => 'paymentSubmitResponse.min.js'], ['priority' => 301, 'filename' => 'bit-razorpay-field.min.js'], ['priority' => 601, 'filename' => 'Razorpay', 'scriptTyp' => 'init', 'source' => $initSource], ], 'radio' => [ ['priority' => 301, 'filename' => 'OtherOptionJS', 'scriptTyp' => 'custom', 'source' => $customSource], ], 'check' => [ ['priority' => 301, 'filename' => 'OtherOptionJS', 'scriptTyp' => 'custom', 'source' => $customSource], ['priority' => 301, 'filename' => 'CheckDisableOnMax', 'scriptTyp' => 'custom', 'source' => $customSource], ], 'recaptcha' => [ ['priority' => 301, 'filename' => 'bit-recaptcha-field.min.js'], ['priority' => 601, 'filename' => 'Recaptcha', 'scriptTyp' => 'init', 'source' => $initSource], ], 'decision-box' => [ ['priority' => 101, 'filename' => 'decisionFldHandle.min.js'], ] ]; } public static function filePondPlugins($plugin) { $plugins = [ 'allowFileSizeValidation' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-file-validate-size.min.js'], 'allowFileTypeValidation' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-file-validate-type.min.js'], 'allowImageCrop' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-crop.min.js'], 'allowImagePreview' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-preview.min.js'], 'allowImageResize' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-resize.min.js'], 'allowImageTransform' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-transform.min.js'], 'allowImageValidateSize' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-validate-size.min.js'], 'allowPreview' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-media-preview.min.js'], ]; if (array_key_exists($plugin, $plugins)) { return $plugins[$plugin]; } return false; } public static function fieldMissingConfigsProps($fieldType, $field) { // key is config path, value is field path // var is for variable value // path is for field path // val is for static value $configs = [ 'select' => [ 'fieldKey' => ['var' => 'fieldKey'], 'options' => ['path' => 'optionsList'], 'placeholder' => ['path' => 'ph'], 'classNames' => ['path' => 'customClasses'], 'attributes' => ['path' => 'customAttributes'], 'defaultValue' => ['path' => 'val', 'val' => isset($field->config->defaultValue) ? $field->config->defaultValue : ''], 'separator' => ['val' => BITFORMS_BF_SEPARATOR], 'mn' => ['path' => 'mn', 'val' => 0], 'mx' => ['path' => 'mx', 'val' => 0], 'disableOnMax' => ['path' => 'valid->disableOnMax', 'val' => false], ], 'country' => [ 'fieldKey' => ['var' => 'fieldKey'], 'options' => ['path' => 'options'], 'placeholder' => ['path' => 'ph'], 'assetsURL' => ['val' => BITFORMS_ROOT_URI . '/static/countries/'], 'classNames' => ['path' => 'customClasses'], 'attributes' => ['path' => 'customAttributes'], 'defaultValue' => ['path' => 'val', 'val' => isset($field->config->defaultValue) ? $field->config->defaultValue : ''], ], 'currency' => [ 'fieldKey' => ['var' => 'fieldKey'], 'options' => ['path' => 'options'], 'assetsURL' => ['val' => BITFORMS_ROOT_URI . '/static/currencies/'], 'classNames' => ['path' => 'customClasses'], 'attributes' => ['path' => 'customAttributes'], 'defaultValue' => ['path' => 'val', 'val' => isset($field->config->defaultValue) ? $field->config->defaultValue : ''], ], 'phone-number' => [ 'fieldKey' => ['var' => 'fieldKey'], 'options' => ['path' => 'options'], 'assetsURL' => ['val' => BITFORMS_ROOT_URI . '/static/countries/'], 'classNames' => ['path' => 'customClasses'], 'attributes' => ['path' => 'customAttributes'] ], 'file-up' => [ 'fieldKey' => ['var' => 'fieldKey'], 'maxSizeErrMsg' => ['path' => isset($field->err->maxSize->msg) ? 'err->maxSize->msg' : 'err->maxSize->dflt'], 'minFileErrMsg' => ['path' => isset($field->err->minFile->msg) ? 'err->minFile->msg' : 'err->minFile->dflt'], 'maxFileErrMsg' => ['path' => isset($field->err->maxFile->msg) ? 'err->maxFile->msg' : 'err->maxFile->dflt'], 'assetsURL' => ['val' => BITFORMS_ROOT_URI . '/static/file-upload/'], 'classNames' => ['path' => 'customClasses'], 'attributes' => ['path' => 'customAttributes'] ], 'paypal' => [ 'payIntegID' => ['path' => 'payIntegID'], 'style' => ['path' => 'style'], 'currency' => ['path' => 'currency', 'val' => 'USD'], 'amount' => ['path' => 'amount', 'val' => 0], 'amountFld' => ['path' => 'amountFld', 'val' => ''], 'shipping' => ['path' => 'shipping', 'val' => 0], 'shippingVal' => ['path' => 'shippingFld', 'val' => ''], 'tax' => ['path' => 'tax', 'val' => 0], 'taxVal' => ['path' => 'taxFld', 'val' => ''], 'description' => ['path' => 'description', 'val' => ''], 'descFld' => ['path' => 'descFld', 'val' => ''], 'payType' => ['path' => 'payType', 'val' => 'payment'], 'planId' => ['path' => 'planId', 'val' => ''], 'locale' => ['path' => 'locale', 'val' => 'en_US'], 'disableFunding' => ['path' => 'disableFunding', 'val' => ''], ], 'advanced-file-up' => [ 'fieldKey' => ['var' => 'fieldKey'], 'formID' => ['var' => 'formID'], 'configSetting' => ['path' => 'config'], 'ajaxURL' => ['val' => admin_url('admin-ajax.php')], 'nonce' => ['val' => wp_create_nonce('bitforms_save')], 'uploadFileToServer' => ['val' => 1], ], 'razorpay' => [ 'fieldKey' => ['var' => 'fieldKey'], 'options' => ['path' => 'options'], 'payIntegID' => ['path' => 'payIntegID'], 'payType' => ['path' =>'payType', 'val' => ''], ], ]; return isset($configs[$fieldType]) ? $configs[$fieldType] : []; } public static function frontendScriptFile() { return [ 'observeElm' => ['priority' => 101, 'filename' => 'observeElm.min.js'], 'hidden-token-field' => ['priority' => 300, 'filename' => 'hidden-token-field.min.js'], ]; } public static function validationScriptFile() { return [ 'checkFldValidation' => ['priority' => 701, 'filename' => 'checkFldValidation.min.js'], 'checkMinMaxOptions' => ['priority' => 702, 'filename' => 'checkMinMaxOptions.min.js'], 'customOptionValidation' => ['priority' => 702, 'filename' => 'customOptionValidation.min.js'], 'dcsnbxFldValidation' => ['priority' => 702, 'filename' => 'dcsnbxFldValidation.min.js'], 'emailFldValidation' => ['priority' => 702, 'filename' => 'emailFldValidation.min.js'], 'fileupFldValidation' => ['priority' => 702, 'filename' => 'fileupFldValidation.min.js'], 'advanceFileupFldValidation' => ['priority' => 702, 'filename' => 'advanceFileUpFldValidation.min.js'], 'phoneNumberFldValidation' => ['priority' => 702, 'filename' => 'phoneNumberFldValidation.min.js'], 'generateBackslashPattern' => ['priority' => 700, 'filename' => 'generateBackslashPattern.min.js'], 'nmbrFldValidation' => ['priority' => 702, 'filename' => 'nmbrFldValidation.min.js'], 'regexPatternValidation' => ['priority' => 701, 'filename' => 'regexPatternValidation.min.js'], // load before generateBackslashPattern file, then load regexPatternValidation 'requiredFldValidation' => ['priority' => 700, 'filename' => 'requiredFldValidation.min.js'], 'urlFldValidation' => ['priority' => 702, 'filename' => 'urlFldValidation.min.js'], 'validation' => ['priority' => 705, 'filename' => 'validateForm.min.js'], // last priority for validation script 'conditionalLogic' => ['priority' => 705, 'filename' => 'bit-conditionals.min.js'], // last priority for validation script 'validateFocusLost' => ['priority' => 706, 'filename' => 'validate-focus.min.js'], // last priority for validation script ]; } public static function validationCommonFunction() { $commonFunctions = [ 'requiredFldValidation' => [ 'fields' => ['text', 'email'] // string { all} or array {field name} of field types ], 'commonFuncion2' => [ 'notFields' => ['text', 'email'], 'dependencies' => ['someDependsOnThisField'], 'paths' => ['path1', 'path2'], ], ]; return $commonFunctions; } public static function validationScriptFileMapping($fieldType) { $textTypeField = ['text', 'password', 'username', 'url', 'date', 'datetime-local', 'time', 'month', 'week', 'color']; if (in_array($fieldType, $textTypeField)) { $fieldType = 'text'; } $fields = [ 'text' => [ 'regexPatternValidation' => [ 'paths' => ['valid->regexr'], 'dependencies' => [ 'generateBackslashPattern' ] ] ], 'email' => [ 'emailFldValidation' => [ 'paths' => ['err->invalid->show'], 'dependencies' => [ 'generateBackslashPattern' ] ], ], 'number' => [ 'nmbrFldValidation' => [ 'paths' => ['mn', 'mx'] ] ], 'radio' => [ 'customOptionValidation' => [ 'paths' => ['valid->otherOptReq'], ] ], 'check' => [ 'checkMinMaxOptions' => [ 'paths' => ['mn', 'mx'], 'dependencies' => [ 'checkFldValidation' ] ], 'customOptionValidation' => [ 'paths' => ['valid->otherOptReq'], ] ], 'select' => [ 'checkMinMaxOptions' => [ 'paths' => ['mn', 'mx'], 'dependencies' => [ 'checkFldValidation' ] ], ], 'url' => [ 'urlFldValidation' => [ 'paths' => ['err->invalid->show'], 'dependencies' => [ 'generateBackslashPattern' ] ] ], 'decision-box' => [ 'dcsnbxFldValidation' => [ 'paths' => ['valid->req'] ] ], 'file-up' => [ 'fileupFldValidation' => [ 'paths' => ['valid->req'] ] ], 'advanced-file-up' => [ 'advanceFileupFldValidation' => [ 'paths' => ['valid->req'] ] ], 'phone-number' => [ 'phoneNumberFldValidation' => [ 'paths' => ['err->invalid->show'], ] ], ]; return isset($fields[$fieldType]) ? $fields[$fieldType] : []; } }