PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
← All changes | templates/fields/calculated-field.php +63 -38 1.1.1 → 3.6.6 View file →
@@ -1,38 +1,63 @@
1 -<?php
2 -/**
3 - * Calculated field template
4 - */
5 -$calc_data = $this->get_calculated_data( $args );
6 -
7 -if ( empty( $calc_data['formula'] ) ){
8 - return;
9 -}
10 -
11 -$name = $this->block_type->get_field_name( $args['name'] );
12 -$default_value = ! empty( $args['default'] ) ? $args['default'] : '';
13 -$prefix = ! empty( $args['calc_prefix'] ) ? $args['calc_prefix'] : false;
14 -$suffix = ! empty( $args['calc_suffix'] ) ? $args['calc_suffix'] : false;
15 -$precision = isset( $args['precision'] ) ? $args['precision'] : 0;
16 -
17 -$this->add_attribute( 'data-formula', $calc_data['formula'] );
18 -$this->add_attribute( 'data-name', $args['name'] );
19 -$this->add_attribute( 'data-listen_to', htmlspecialchars( json_encode( $calc_data['listen_fields'] ) ) );
20 -$this->add_attribute( 'data-precision', $precision );
21 -
22 -if ( ! empty( $this->live_form->current_repeater ) ) {
23 - $class_name = 'jet-form-builder__calculated-field--child';
24 -} else {
25 - $class_name = 'jet-form-builder__calculated-field';
26 -}
27 -
28 -?>
29 -<div class="<?php echo $class_name; ?>"<?php $this->render_attributes_string(); ?>>
30 - <?php if ( false !== $prefix ) : ?>
31 - <div class="jet-form-builder__calculated-field-prefix"><?php echo $prefix; ?></div>
32 - <?php endif; ?>
33 - <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $default_value; ?>" class="jet-form-builder__calculated-field-input jet-form-builder__field" data-field-name="<?php echo $args['name']; ?>">
34 - <div class="jet-form-builder__calculated-field-val"><?php echo $this->render_editor_placeholder(); ?></div>
35 - <?php if ( false !== $suffix ) : ?>
36 - <div class="jet-form-builder__calculated-field-suffix"><?php echo $suffix; ?></div>
37 - <?php endif; ?>
38 -</div>
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 +$this->add_attribute( 'data-date-format', ! empty( $args['date_format'] ) ? $args['date_format'] : 'YYYY-MM-DD' );
38 +
39 +$this->add_attribute( 'class', 'jet-form-builder__calculated-field' );
40 +$this->add_attribute( 'class', $is_hidden ? 'jet-form-builder__calculated-field--hidden' : '' );
41 +
42 +// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WhiteSpace.PrecisionAlignment.Found
43 +?>
44 +<div <?php $this->render_attributes_string(); ?>>
45 + <?php do_action( 'jet-form-builder/before-field', $this ); ?>
46 + <?php if ( false !== $prefix ) : ?>
47 + <div class="jet-form-builder__calculated-field-prefix"><?php echo wp_kses_post( $prefix ); ?></div>
48 + <?php endif; ?>
49 + <input type="hidden"
50 + name="<?php echo esc_attr( $name ); ?>"
51 + id="<?php echo esc_attr( $id_attr ); ?>"
52 + value="<?php echo esc_attr( $default_value ); ?>"
53 + class="jet-form-builder__calculated-field-input jet-form-builder__field"
54 + data-field-name="<?php echo esc_attr( $args['name'] ); ?>"
55 + data-jfb-sync
56 + />
57 + <div class="jet-form-builder__calculated-field-val"><?php echo wp_kses_post( $this->render_editor_placeholder() ); ?></div>
58 + <?php if ( false !== $suffix ) : ?>
59 + <div class="jet-form-builder__calculated-field-suffix"><?php echo wp_kses_post( $suffix ); ?></div>
60 + <?php endif; ?>
61 + <?php do_action( 'jet-form-builder/after-field', $this ); ?>
62 +</div>
63 +<?php