action-button.php
2 years ago
calculated-field.php
2 years ago
color-picker-field.php
2 years ago
date-field.php
2 years ago
datetime-field.php
2 years ago
form-break-field.php
2 years ago
group-break-field.php
2 years ago
heading-field.php
2 years ago
hidden-field.php
2 years ago
image-preview.php
2 years ago
media-field.php
2 years ago
number-field.php
2 years ago
preset-media-field.php
2 years ago
progress-bar.php
2 years ago
range-field.php
2 years ago
textarea-field.php
2 years ago
time-field.php
2 years ago
calculated-field.php
63 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Calculated field template |
| 4 | * |
| 5 | * @var Calculated_Field_Render $this |
| 6 | * @var $args |
| 7 | */ |
| 8 | |
| 9 | use Jet_Form_Builder\Blocks\Render\Calculated_Field_Render; |
| 10 | |
| 11 | // If this file is called directly, abort. |
| 12 | if ( ! defined( 'WPINC' ) ) { |
| 13 | die; |
| 14 | } |
| 15 | |
| 16 | $formula = $this->get_calculated_data( $args ); |
| 17 | |
| 18 | if ( empty( $formula ) ) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | $name = $this->block_type->get_field_name( $args['name'] ); |
| 23 | $id_attr = $this->block_type->get_field_id(); |
| 24 | $default_value = ! empty( $args['default'] ) ? $args['default'] : ''; |
| 25 | $prefix = ! empty( $args['calc_prefix'] ) ? $args['calc_prefix'] : false; |
| 26 | $suffix = ! empty( $args['calc_suffix'] ) ? $args['calc_suffix'] : false; |
| 27 | $precision = isset( $args['precision'] ) ? $args['precision'] : 0; |
| 28 | $is_hidden = isset( $args['calc_hidden'] ) ? filter_var( $args['calc_hidden'], defined( 'FILTER_VALIDATE_BOOL' ) ? FILTER_VALIDATE_BOOL : FILTER_VALIDATE_BOOLEAN ) : false; |
| 29 | |
| 30 | $this->add_attribute( 'class', $args['class_name'] ); |
| 31 | $this->add_attribute( 'data-formula', $formula ); |
| 32 | $this->add_attribute( 'data-name', $args['name'] ); |
| 33 | $this->add_attribute( 'data-precision', $precision ); |
| 34 | $this->add_attribute( 'data-sep-decimal', $args['separate_decimals'] ); |
| 35 | $this->add_attribute( 'data-sep-thousands', $args['separate_thousands'] ); |
| 36 | $this->add_attribute( 'data-value-type', $this->args['value_type'] ); |
| 37 | |
| 38 | $this->add_attribute( 'class', 'jet-form-builder__calculated-field' ); |
| 39 | $this->add_attribute( 'class', $is_hidden ? 'jet-form-builder__calculated-field--hidden' : '' ); |
| 40 | |
| 41 | // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WhiteSpace.PrecisionAlignment.Found |
| 42 | ?> |
| 43 | <div <?php $this->render_attributes_string(); ?>> |
| 44 | <?php do_action( 'jet-form-builder/before-field', $this ); ?> |
| 45 | <?php if ( false !== $prefix ) : ?> |
| 46 | <div class="jet-form-builder__calculated-field-prefix"><?php echo wp_kses_post( $prefix ); ?></div> |
| 47 | <?php endif; ?> |
| 48 | <input type="hidden" |
| 49 | name="<?php echo esc_attr( $name ); ?>" |
| 50 | id="<?php echo esc_attr( $id_attr ); ?>" |
| 51 | value="<?php echo esc_attr( $default_value ); ?>" |
| 52 | class="jet-form-builder__calculated-field-input jet-form-builder__field" |
| 53 | data-field-name="<?php echo esc_attr( $args['name'] ); ?>" |
| 54 | data-jfb-sync |
| 55 | /> |
| 56 | <div class="jet-form-builder__calculated-field-val"><?php echo wp_kses_post( $this->render_editor_placeholder() ); ?></div> |
| 57 | <?php if ( false !== $suffix ) : ?> |
| 58 | <div class="jet-form-builder__calculated-field-suffix"><?php echo wp_kses_post( $suffix ); ?></div> |
| 59 | <?php endif; ?> |
| 60 | <?php do_action( 'jet-form-builder/after-field', $this ); ?> |
| 61 | </div> |
| 62 | <?php |
| 63 |