| @@ -5,10 +5,10 @@ | ||
| 5 | 5 | GFForms::include_addon_framework(); |
| 6 | 6 | class Superaddons_Grepeater_Field_Addon extends GFAddOn{ |
| 7 | 7 | protected $_version = "1.0"; |
| 8 | 8 | protected $_min_gravityforms_version = '1.9'; |
| 9 | - protected $_slug = 'gravityforms-repeater'; | |
| 10 | - protected $_path = 'gravityforms-repeater/index.php'; | |
| 9 | + protected $_slug = 'repeater-for-gravity-forms'; | |
| 10 | + protected $_path = 'repeater-for-gravity-forms/repeater-for-gravity-forms.php'; | |
| 11 | 11 | protected $_full_path = __FILE__; |
| 12 | 12 | protected $_title = 'Gravity Forms Repeater Fields Add-On'; |
| 13 | 13 | protected $_short_title = 'Gravity Repeater'; |
| 14 | 14 | private static $_instance = null; |
| @@ -19,82 +19,30 @@ | ||
| 19 | 19 | return self::$_instance; |
| 20 | 20 | } |
| 21 | 21 | public function init_admin() { |
| 22 | 22 | parent::init_admin(); |
| 23 | - // add tasks or filters here that you want to perform only in admin | |
| 24 | 23 | } |
| 25 | 24 | public function init_frontend() { |
| 26 | 25 | parent::init_frontend(); |
| 27 | 26 | // add tasks or filters here that you want to perform only in the front end |
| 28 | 27 | } |
| 29 | - function type( $position, $form_id ) { | |
| 30 | - $check_pro = get_option( '_redmuber_item_1540'); | |
| 28 | + function type( $position, $form_id ) { | |
| 31 | 29 | if ( $position == 1550 ) { |
| 32 | - ?> | |
| 33 | - <li class="field_field_repeater_title_setting field_setting"> | |
| 30 | + ?> | |
| 31 | + <li class="field_field_repeater_title_setting field_setting"> | |
| 34 | 32 | <label class="section_label"> |
| 35 | - <?php esc_html_e('Title', 'gravityforms-repeater'); ?> | |
| 33 | + <?php esc_html_e('Title', 'repeater-for-gravity-forms'); ?> | |
| 36 | 34 | </label> |
| 37 | 35 | <input type="text" id="repeater_title" placeholder="Person" value="" onchange="SetFieldProperty('repeater_title', this.value);"> |
| 38 | - <?php esc_html_e("An optional title before each row of the repeater",'gravityforms-repeater') ?> | |
| 36 | + <?php esc_html_e("An optional title before each row of the repeater",'repeater-for-gravity-forms') ?> | |
| 39 | 37 | </li> |
| 40 | - <?php if($check_pro == "ok") {?> | |
| 41 | - <li class="field_field_repeater_initial_rows_setting field_setting"> | |
| 42 | - <label class="section_label"> | |
| 43 | - <?php esc_html_e('Initial Rows', 'gravityforms-repeater'); ?> | |
| 44 | - </label> | |
| 45 | - <input type="text" id="repeater_initial_rows" placeholder="1" value="" onchange="SetFieldProperty('repeater_initial_rows', this.value);"> | |
| 46 | - <?php esc_html_e("The number of rows at start, if empty no rows will be created",'gravityforms-repeater') ?> | |
| 47 | - </li> | |
| 48 | - <li class="field_field_repeater_initial_rows_setting field_setting"> | |
| 49 | - <label class="section_label"> | |
| 50 | - <?php esc_html_e('Map field with Initial Rows', 'gravityforms-repeater'); ?> | |
| 51 | - </label> | |
| 52 | - <input type="text" id="repeater_initial_rows_map" placeholder="" value="" onchange="SetFieldProperty('repeater_initial_rows_map', this.value);"> | |
| 53 | - <?php esc_html_e("Map field with Initial Rows (ID field)",'gravityforms-repeater') ?> | |
| 54 | - </li> | |
| 55 | - <li class="field_field_repeater_max_setting field_setting"> | |
| 56 | - <label class="section_label"> | |
| 57 | - <?php esc_html_e('Limit', 'gravityforms-repeater'); ?> | |
| 58 | - </label> | |
| 59 | - <input type="text" id="repeater_max" placeholder="9999" value="" onchange="SetFieldProperty('repeater_max', this.value);"> | |
| 60 | - <?php esc_html_e("Max number of rows applicable by the user, leave empty for no limit",'gravityforms-repeater') ?> | |
| 61 | - </li> | |
| 62 | - <?php }else{ ?> | |
| 63 | - <li class="field_field_repeater_initial_rows_setting field_setting"> | |
| 64 | - <label class="section_label"> | |
| 65 | - <?php esc_html_e('Initial Rows', 'gravityforms-repeater'); ?> | |
| 66 | - </label> | |
| 67 | - <div class="pro_disable"> | |
| 68 | - <input type="text" id="repeater_initial_rows" placeholder="Upgrade to pro version" value="" readonly="true"> | |
| 69 | - </div> | |
| 70 | - <?php esc_html_e("The number of rows at start, if empty no rows will be created",'gravityforms-repeater') ?> | |
| 71 | - </li> | |
| 72 | - <li class="field_field_repeater_initial_rows_setting field_setting"> | |
| 73 | - <label class="section_label"> | |
| 74 | - <?php esc_html_e('Map field with Initial Rows', 'gravityforms-repeater'); ?> | |
| 75 | - </label> | |
| 76 | - <div class="pro_disable"> | |
| 77 | - <input type="text" id="repeater_initial_rows_map" placeholder="Upgrade to pro version" value="" readonly="true" > | |
| 78 | - </div> | |
| 79 | - <?php esc_html_e("Map field with Initial Rows (ID field)",'gravityforms-repeater') ?> | |
| 80 | - </li> | |
| 81 | - <li class="field_field_repeater_max_setting field_setting"> | |
| 82 | - <label class="section_label"> | |
| 83 | - <?php esc_html_e('Limit', 'gravityforms-repeater'); ?> | |
| 84 | - </label> | |
| 85 | - <input type="text" id="repeater_max" placeholder="5" value="" onchange="SetFieldProperty('repeater_max', this.value);"> | |
| 86 | - <?php esc_html_e("Max number of rows applicable by the user, leave empty for no limit (Free version limit = 5 )",'gravityforms-repeater') ?> | |
| 87 | - </li> | |
| 88 | - <?php } ?> | |
| 89 | - | |
| 90 | - | |
| 38 | + <?php do_action( "yeeaddons_gf_repeater_settings") ?> | |
| 91 | 39 | <li class="field_field_repeater_end_text_setting field_setting"> |
| 92 | 40 | <label class="section_label"> |
| 93 | - <?php esc_html_e('Text button', 'gravityforms-repeater'); ?> | |
| 41 | + <?php esc_html_e('Text button', 'repeater-for-gravity-forms'); ?> | |
| 94 | 42 | </label> |
| 95 | 43 | <input type="text" id="field_repeater_end_text" placeholder="Add more" value="" onchange="SetFieldProperty('field_repeater_end_text', this.value);"> |
| 96 | - <?php esc_html_e("add button text",'gravityforms-repeater') ?> | |
| 44 | + <?php esc_html_e("add button text",'repeater-for-gravity-forms') ?> | |
| 97 | 45 | </li> |
| 98 | 46 | <?php |
| 99 | 47 | } |
| 100 | 48 | } |
| @@ -117,31 +65,52 @@ | ||
| 117 | 65 | <?php |
| 118 | 66 | } |
| 119 | 67 | public function pre_init() { |
| 120 | 68 | parent::pre_init(); |
| 69 | + add_filter( "gform_input_mask_script",array($this,"gform_input_mask_script"),10,4 ); | |
| 121 | 70 | add_action( 'gform_field_standard_settings', array($this,'type'), 10, 2 ); |
| 122 | 71 | add_action( 'gform_editor_js', array($this,'editor_script') ); |
| 123 | 72 | include SUPERADDONS_GF_REPEATER_PLUGIN_PATH."fields/repeater_field.php"; |
| 124 | 73 | include SUPERADDONS_GF_REPEATER_PLUGIN_PATH."fields/repeater_start_field.php"; |
| 125 | 74 | add_filter( 'gform_pre_validation', array( "Superaddons_GFRepeater_Field", 'remove_validation' ) ); |
| 75 | + add_filter( 'gform_admin_pre_render', array( 'Superaddons_GFRepeater_Field', 'remove_child_fields' ) ); | |
| 76 | + add_filter( 'gform_form_post_get_meta', array( 'Superaddons_GFRepeater_Field', 'remove_child_fields' ) ); | |
| 77 | + add_filter( 'gform_submission_values_pre_save', array( 'Superaddons_GFRepeater_Field', 'save_draft_submission_values' ), 10, 2 ); | |
| 78 | + add_action( 'gform_enqueue_scripts', array($this,"add_data"),10,2 ); | |
| 126 | 79 | } |
| 127 | - public function scripts() { | |
| 128 | - if(!is_admin()){ | |
| 129 | - $scripts = array( | |
| 130 | - array( | |
| 131 | - 'handle' => 'gf_repeater', | |
| 132 | - 'src' => SUPERADDONS_GF_REPEATER_PLUGIN_URL."libs/wp_repeater.js", | |
| 133 | - 'version' => time(), | |
| 134 | - 'deps' => array( 'jquery'), | |
| 135 | - 'enqueue' => array( | |
| 136 | - array( 'field_types' => array( 'repeater_end' ) ), | |
| 137 | - ), | |
| 138 | - ), | |
| 139 | - ); | |
| 140 | - return array_merge( parent::scripts(), $scripts ); | |
| 141 | - }else{ | |
| 142 | - return parent::scripts(); | |
| 80 | + function gform_input_mask_script($script_str,$form_id,$field_id,$mask){ | |
| 81 | + $input_mask = get_option( "yeeaddons_gf_input_mask",array()); | |
| 82 | + $input_mask["input_".$form_id."_".$field_id] = esc_js( $mask ); | |
| 83 | + update_option( "yeeaddons_gf_input_mask",$input_mask ); | |
| 84 | + return $script_str; | |
| 85 | + } | |
| 86 | + function add_data($form, $is_ajax ){ | |
| 87 | + $input_mask = get_option( "yeeaddons_gf_input_mask",array()); | |
| 88 | + if ( isset( $form['fields'] ) && is_array( $form['fields'] ) ) { | |
| 89 | + foreach ( $form['fields'] as $field ) { | |
| 90 | + // 1. Các trường Text / Field thường tick "Input Mask" | |
| 91 | + if ( ! empty( $field->inputMask ) && ! empty( $field->inputMaskValue ) ) { | |
| 92 | + $input_mask["input_" . $form['id'] . "_" . $field->id] = (string) $field->inputMaskValue; | |
| 93 | + } | |
| 94 | + // 2. Các trường Phone | |
| 95 | + if ( isset( $field->type ) && $field->type === 'phone' ) { | |
| 96 | + $phone_format = method_exists( $field, 'get_phone_format' ) ? $field->get_phone_format() : array(); | |
| 97 | + $mask = isset( $phone_format['mask'] ) ? $phone_format['mask'] : ''; | |
| 98 | + if ( empty( $mask ) && ( ! isset( $field->phoneFormat ) || $field->phoneFormat === 'standard' || empty( $field->phoneFormat ) ) ) { | |
| 99 | + $mask = '(999) 999-9999'; | |
| 100 | + } | |
| 101 | + if ( ! empty( $mask ) ) { | |
| 102 | + $input_mask["input_" . $form['id'] . "_" . $field->id] = (string) $mask; | |
| 103 | + } | |
| 104 | + } | |
| 105 | + } | |
| 143 | 106 | } |
| 107 | + if ( ! wp_script_is( 'gform_masked_input', 'registered' ) ) { | |
| 108 | + wp_register_script( 'gform_masked_input', SUPERADDONS_GF_REPEATER_PLUGIN_URL . 'libs/jquery.maskedinput.min.js', array( 'jquery' ), '1.3.1', true ); | |
| 109 | + } | |
| 110 | + wp_enqueue_script( 'gf_repeater', SUPERADDONS_GF_REPEATER_PLUGIN_URL . "libs/wp_repeater.js", array( 'jquery', 'gform_masked_input' ), time() ); | |
| 111 | + $check_pro = get_option( '_redmuber_item_1540' ); | |
| 112 | + wp_localize_script( "gf_repeater", "yeeaddons_gf_repeater_data", array( "input_mask" => ( $input_mask ), "pro" => $check_pro ) ); | |
| 144 | 113 | } |
| 145 | 114 | public function styles() { |
| 146 | 115 | $styles = array( |
| 147 | 116 | array( |