number_formats.php
275 lines
| 1 | <?php |
| 2 | namespace ElementorPro\Modules\Forms\Fields; |
| 3 | use Elementor\Widget_Base; |
| 4 | use ElementorPro\Modules\Forms\Classes; |
| 5 | use Elementor\Controls_Manager; |
| 6 | use ElementorPro\Plugin; |
| 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | exit; // Exit if accessed directly |
| 9 | } |
| 10 | class Number_Format_Cost_Calculator extends Field_Base { |
| 11 | public function get_type() { |
| 12 | return 'number_format'; |
| 13 | } |
| 14 | public function get_name() { |
| 15 | return esc_html__( 'Number Format', 'cost-calculator-for-elementor' ); |
| 16 | } |
| 17 | public function editor_preview_footer() { |
| 18 | add_action( 'wp_footer', array($this,"field_template_script")); |
| 19 | } |
| 20 | public function __construct() { |
| 21 | parent::__construct(); |
| 22 | add_action( 'elementor/preview/init', array( $this, 'editor_preview_footer' ) ); |
| 23 | } |
| 24 | function field_template_script(){ |
| 25 | ?> |
| 26 | <script> |
| 27 | jQuery( document ).ready( () => { |
| 28 | elementor.hooks.addFilter( |
| 29 | 'elementor_pro/forms/content_template/field/number_format', |
| 30 | function ( inputField, item, i ) { |
| 31 | const fieldId = `form_field_${i}`; |
| 32 | const fieldClass = `elementor-field elementor-size-sm elementor-field-textual ${item.css_classes}`; |
| 33 | const size = '1'; |
| 34 | return `<input placeholder="Number Format" type="text" id="${fieldId}" class="${fieldClass}">`; |
| 35 | }, 10, 3 |
| 36 | ); |
| 37 | }); |
| 38 | </script> |
| 39 | <?php |
| 40 | } |
| 41 | public function render( $item, $item_index, $form ) { |
| 42 | $form->remove_render_attribute( 'input' . $item_index, 'type' ); |
| 43 | $form->add_render_attribute( 'input' . $item_index, 'type', 'text' ); |
| 44 | if ( isset( $item['field_min'] ) ) { |
| 45 | $form->add_render_attribute( 'input' . $item_index, 'min', esc_attr( $item['field_min'] ) ); |
| 46 | } |
| 47 | if ( isset( $item['field_max'] ) ) { |
| 48 | $form->add_render_attribute( 'input' . $item_index, 'max', esc_attr( $item['field_max'] ) ); |
| 49 | } |
| 50 | $form->add_render_attribute( 'input' . $item_index, 'class', 'elementor-field-textual elementor-number-format' ); |
| 51 | $form->add_render_attribute( 'input' . $item_index, 'data-a-sign', esc_attr( $item['number_format_symbols1'] ) ); |
| 52 | $form->add_render_attribute( 'input' . $item_index, 'data-a-dec', esc_attr( $item['number_format_decimal_sep1'] ) ); |
| 53 | $form->add_render_attribute( 'input' . $item_index, 'data-a-sep', esc_attr( $item['number_format_thousand_sep1'] ) ); |
| 54 | $form->add_render_attribute( 'input' . $item_index, 'data-m-dec', esc_attr( $item['number_format_num_decimals1'] ) ); |
| 55 | if( $item['number_format_symbols_position1'] == "right" ){ |
| 56 | $form->add_render_attribute( 'input' . $item_index, 'data-p-sign', 's'); |
| 57 | } |
| 58 | ?> |
| 59 | <input <?php $form->print_render_attribute_string( 'input' . $item_index ); ?> > |
| 60 | <?php |
| 61 | } |
| 62 | /** |
| 63 | * @param Widget_Base $widget |
| 64 | */ |
| 65 | public function update_controls( $widget ) { |
| 66 | $elementor = Plugin::elementor(); |
| 67 | $control_data = $elementor->controls_manager->get_control_from_stack( $widget->get_unique_name(), 'form_fields' ); |
| 68 | if ( is_wp_error( $control_data ) ) { |
| 69 | return; |
| 70 | } |
| 71 | $check = get_option( '_redmuber_item_1529'); |
| 72 | if( $check == "ok" ){ |
| 73 | $field_controls = [ |
| 74 | 'field_min1' => [ |
| 75 | 'name' => 'field_min1', |
| 76 | 'label' => esc_html__( 'Min. Value', 'cost-calculator-for-elementor' ), |
| 77 | 'type' => Controls_Manager::NUMBER, |
| 78 | 'condition' => [ |
| 79 | 'field_type' => $this->get_type(), |
| 80 | ], |
| 81 | 'tab' => 'content', |
| 82 | 'inner_tab' => 'form_fields_content_tab', |
| 83 | 'tabs_wrapper' => 'form_fields_tabs', |
| 84 | ], |
| 85 | 'field_max1' => [ |
| 86 | 'name' => 'field_max1', |
| 87 | 'label' => esc_html__( 'Max. Value', 'cost-calculator-for-elementor' ), |
| 88 | 'type' => Controls_Manager::NUMBER, |
| 89 | 'condition' => [ |
| 90 | 'field_type' => $this->get_type(), |
| 91 | ], |
| 92 | 'tab' => 'content', |
| 93 | 'inner_tab' => 'form_fields_content_tab', |
| 94 | 'tabs_wrapper' => 'form_fields_tabs', |
| 95 | ], |
| 96 | 'number_format_symbols1' => [ |
| 97 | 'name' => 'number_format_symbols1', |
| 98 | 'label' => esc_html__( 'Symbols', 'cost-calculator-for-elementor' ), |
| 99 | 'type' => Controls_Manager::TEXT, |
| 100 | 'condition' => [ |
| 101 | 'field_type' => $this->get_type(), |
| 102 | ], |
| 103 | 'tab' => 'content', |
| 104 | 'inner_tab' => 'form_fields_content_tab', |
| 105 | 'tabs_wrapper' => 'form_fields_tabs', |
| 106 | ], |
| 107 | 'number_format_symbols_position1' => [ |
| 108 | 'name' => 'number_format_symbols_position1', |
| 109 | 'label' => esc_html__( 'Symbols Position', 'cost-calculator-for-elementor' ), |
| 110 | 'type' => Controls_Manager::SELECT, |
| 111 | 'options'=> array("left"=>"Left","right"=>"Right"), |
| 112 | 'default' => 'left', |
| 113 | 'condition' => [ |
| 114 | 'field_type' => $this->get_type(), |
| 115 | ], |
| 116 | 'tab' => 'content', |
| 117 | 'inner_tab' => 'form_fields_content_tab', |
| 118 | 'tabs_wrapper' => 'form_fields_tabs', |
| 119 | ], |
| 120 | 'number_format_thousand_sep1' => [ |
| 121 | 'name' => 'number_format_thousand_sep1', |
| 122 | 'label' => esc_html__( 'Thousand separator', 'cost-calculator-for-elementor' ), |
| 123 | 'type' => Controls_Manager::TEXT, |
| 124 | 'default' => ',', |
| 125 | 'condition' => [ |
| 126 | 'field_type' => $this->get_type(), |
| 127 | ], |
| 128 | 'tab' => 'content', |
| 129 | 'inner_tab' => 'form_fields_content_tab', |
| 130 | 'tabs_wrapper' => 'form_fields_tabs', |
| 131 | ], |
| 132 | 'number_format_decimal_sep1' => [ |
| 133 | 'name' => 'number_format_decimal_sep1', |
| 134 | 'label' => esc_html__( 'Decimal separator', 'cost-calculator-for-elementor' ), |
| 135 | 'type' => Controls_Manager::TEXT, |
| 136 | 'default' => '.', |
| 137 | 'condition' => [ |
| 138 | 'field_type' => $this->get_type(), |
| 139 | ], |
| 140 | 'tab' => 'content', |
| 141 | 'inner_tab' => 'form_fields_content_tab', |
| 142 | 'tabs_wrapper' => 'form_fields_tabs', |
| 143 | ], |
| 144 | 'number_format_num_decimals1' => [ |
| 145 | 'name' => 'number_format_num_decimals1', |
| 146 | 'label' => esc_html__( 'Number Decimals', 'cost-calculator-for-elementor' ), |
| 147 | 'type' => Controls_Manager::NUMBER, |
| 148 | 'default' => 2, |
| 149 | 'condition' => [ |
| 150 | 'field_type' => $this->get_type(), |
| 151 | ], |
| 152 | 'tab' => 'content', |
| 153 | 'inner_tab' => 'form_fields_content_tab', |
| 154 | 'tabs_wrapper' => 'form_fields_tabs', |
| 155 | ], |
| 156 | ]; |
| 157 | }else{ |
| 158 | $field_controls = [ |
| 159 | 'field_min1' => [ |
| 160 | 'name' => 'field_min1', |
| 161 | 'label' => esc_html__( 'Min. Value', 'cost-calculator-for-elementor' ), |
| 162 | 'type' => Controls_Manager::NUMBER, |
| 163 | 'condition' => [ |
| 164 | 'field_type' => $this->get_type(), |
| 165 | ], |
| 166 | 'tab' => 'content', |
| 167 | 'inner_tab' => 'form_fields_content_tab', |
| 168 | 'tabs_wrapper' => 'form_fields_tabs', |
| 169 | ], |
| 170 | 'field_max1' => [ |
| 171 | 'name' => 'field_max1', |
| 172 | 'label' => esc_html__( 'Max. Value', 'cost-calculator-for-elementor' ), |
| 173 | 'type' => Controls_Manager::NUMBER, |
| 174 | 'condition' => [ |
| 175 | 'field_type' => $this->get_type(), |
| 176 | ], |
| 177 | 'tab' => 'content', |
| 178 | 'inner_tab' => 'form_fields_content_tab', |
| 179 | 'tabs_wrapper' => 'form_fields_tabs', |
| 180 | ], |
| 181 | 'number_format_symbols1' => [ |
| 182 | 'name' => 'number_format_symbols1', |
| 183 | 'label' => esc_html__( 'Symbols', 'cost-calculator-for-elementor' ), |
| 184 | 'type' => Controls_Manager::TEXT, |
| 185 | 'condition' => [ |
| 186 | 'field_type' => $this->get_type(), |
| 187 | ], |
| 188 | 'tab' => 'content', |
| 189 | 'inner_tab' => 'form_fields_content_tab', |
| 190 | 'tabs_wrapper' => 'form_fields_tabs', |
| 191 | ], |
| 192 | 'number_format_symbols_disable' => [ |
| 193 | 'name' => 'number_format_symbols_disable', |
| 194 | 'label' => esc_html__( 'Symbols (pro)', 'cost-calculator-for-elementor' ), |
| 195 | 'type' => Controls_Manager::TEXT, |
| 196 | 'class' => 'd', |
| 197 | 'condition' => [ |
| 198 | 'field_type' => $this->get_type(), |
| 199 | 'number_format' => 'yes' |
| 200 | ], |
| 201 | 'dynamic' => [ |
| 202 | 'active' => true, |
| 203 | ], |
| 204 | 'tab' => 'content', |
| 205 | 'inner_tab' => 'form_fields_content_tab', |
| 206 | 'tabs_wrapper' => 'form_fields_tabs', |
| 207 | ], |
| 208 | 'number_format_symbols_position_disable1' => [ |
| 209 | 'name' => 'number_format_symbols_position_disable1', |
| 210 | 'label' => esc_html__( 'Symbols Position (pro)', 'cost-calculator-for-elementor' ), |
| 211 | 'type' => Controls_Manager::SELECT, |
| 212 | 'options'=> array("left"=>"Left","right"=>"Right"), |
| 213 | 'default' => 'left', |
| 214 | 'condition' => [ |
| 215 | 'field_type' => $this->get_type(), |
| 216 | 'number_format' => 'yes' |
| 217 | ], |
| 218 | 'tab' => 'content', |
| 219 | 'inner_tab' => 'form_fields_content_tab', |
| 220 | 'tabs_wrapper' => 'form_fields_tabs', |
| 221 | ], |
| 222 | 'number_format_thousand_sep_disable1' => [ |
| 223 | 'name' => 'number_format_thousand_sep_disable1', |
| 224 | 'label' => esc_html__( 'Thousand separator (pro)', 'cost-calculator-for-elementor' ), |
| 225 | 'type' => Controls_Manager::TEXT, |
| 226 | 'default' => ',', |
| 227 | 'condition' => [ |
| 228 | 'field_type' => $this->get_type(), |
| 229 | 'number_format' => 'yes' |
| 230 | ], |
| 231 | 'tab' => 'content', |
| 232 | 'inner_tab' => 'form_fields_content_tab', |
| 233 | 'tabs_wrapper' => 'form_fields_tabs', |
| 234 | ], |
| 235 | 'number_format_decimal_sep_disable1' => [ |
| 236 | 'name' => 'number_format_decimal_sep_disable1', |
| 237 | 'label' => esc_html__( 'Decimal separator (pro)', 'cost-calculator-for-elementor' ), |
| 238 | 'type' => Controls_Manager::TEXT, |
| 239 | 'default' => '.', |
| 240 | 'condition' => [ |
| 241 | 'field_type' => $this->get_type(), |
| 242 | 'number_format' => 'yes' |
| 243 | ], |
| 244 | 'tab' => 'content', |
| 245 | 'inner_tab' => 'form_fields_content_tab', |
| 246 | 'tabs_wrapper' => 'form_fields_tabs', |
| 247 | ], |
| 248 | 'number_format_num_decimals_disable1' => [ |
| 249 | 'name' => 'number_format_num_decimals_disable1', |
| 250 | 'label' => esc_html__( 'Number Decimals (pro)', 'cost-calculator-for-elementor' ), |
| 251 | 'type' => Controls_Manager::NUMBER, |
| 252 | 'default' => 2, |
| 253 | 'condition' => [ |
| 254 | 'field_type' => $this->get_type(), |
| 255 | 'number_format' => 'yes' |
| 256 | ], |
| 257 | 'tab' => 'content', |
| 258 | 'inner_tab' => 'form_fields_content_tab', |
| 259 | 'tabs_wrapper' => 'form_fields_tabs', |
| 260 | ], |
| 261 | ]; |
| 262 | } |
| 263 | $control_data['fields'] = $this->inject_field_controls( $control_data['fields'], $field_controls ); |
| 264 | $widget->update_control( 'form_fields', $control_data ); |
| 265 | } |
| 266 | public function validation( $field, Classes\Form_Record $record, Classes\Ajax_Handler $ajax_handler ) { |
| 267 | if ( ! empty( $field['field_max'] ) && $field['field_max'] < (int) $field['value'] ) { |
| 268 | $ajax_handler->add_error( $field['id'], sprintf( esc_html__( 'The value must be less than or equal to %s', 'cost-calculator-for-elementor' ), $field['field_max'] ) ); |
| 269 | } |
| 270 | if ( ! empty( $field['field_min'] ) && $field['field_min'] > (int) $field['value'] ) { |
| 271 | $ajax_handler->add_error( $field['id'], sprintf( esc_html__( 'The value must be greater than or equal %s', 'cost-calculator-for-elementor' ), $field['field_min'] ) ); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | new Number_Format_Cost_Calculator; |