action-button.php
4 years ago
calculated-field.php
4 years ago
checkbox-field.php
4 years ago
color-picker-field.php
4 years ago
date-field.php
4 years ago
datetime-field.php
4 years ago
form-break-field.php
4 years ago
group-break-field.php
4 years ago
heading-field.php
4 years ago
hidden-field.php
4 years ago
media-field.php
4 years ago
number-field.php
4 years ago
progress-bar.php
4 years ago
radio-field.php
4 years ago
range-field.php
4 years ago
select-field.php
4 years ago
submit-field.php
4 years ago
text-field.php
4 years ago
textarea-field.php
4 years ago
time-field.php
4 years ago
wysiwyg-field.php
4 years ago
calculated-field.php
52 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Calculated field template |
| 4 | * |
| 5 | * @var \Jet_Form_Builder\Blocks\Render\Calculated_Field_Render $this |
| 6 | */ |
| 7 | $calc_data = $this->get_calculated_data( $args ); |
| 8 | |
| 9 | if ( empty( $calc_data['formula'] ) ) { |
| 10 | return; |
| 11 | } |
| 12 | |
| 13 | $name = $this->block_type->get_field_name( $args['name'] ); |
| 14 | $default_value = ! empty( $args['default'] ) ? $args['default'] : ''; |
| 15 | $prefix = ! empty( $args['calc_prefix'] ) ? $args['calc_prefix'] : false; |
| 16 | $suffix = ! empty( $args['calc_suffix'] ) ? $args['calc_suffix'] : false; |
| 17 | $precision = isset( $args['precision'] ) ? $args['precision'] : 0; |
| 18 | $is_hidden = isset( $args['calc_hidden'] ) ? filter_var( $args['calc_hidden'], FILTER_VALIDATE_BOOLEAN ) : false; |
| 19 | |
| 20 | $this->add_attribute( 'class', $args['class_name'] ); |
| 21 | $this->add_attribute( 'data-formula', $calc_data['formula'] ); |
| 22 | $this->add_attribute( 'data-name', $args['name'] ); |
| 23 | $this->add_attribute( 'data-listen_to', htmlspecialchars( wp_json_encode( $calc_data['listen_fields'] ) ) ); |
| 24 | $this->add_attribute( 'data-precision', $precision ); |
| 25 | $this->add_attribute( 'data-sep-decimal', $args['separate_decimals'] ); |
| 26 | $this->add_attribute( 'data-sep-thousands', $args['separate_thousands'] ); |
| 27 | |
| 28 | $this->add_attribute( 'class', empty( $this->block_type->get_current_repeater() ) |
| 29 | ? 'jet-form-builder__calculated-field' |
| 30 | : 'jet-form-builder__calculated-field--child' |
| 31 | ); |
| 32 | |
| 33 | $this->add_attribute( 'class', $is_hidden ? 'jet-form-builder__calculated-field--hidden' : '' ); |
| 34 | |
| 35 | // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped |
| 36 | ?> |
| 37 | <div <?php $this->render_attributes_string(); ?>> |
| 38 | <?php if ( false !== $prefix ) : ?> |
| 39 | <div class="jet-form-builder__calculated-field-prefix"><?php echo wp_kses_post( $prefix ); ?></div> |
| 40 | <?php endif; ?> |
| 41 | <input type="hidden" |
| 42 | name="<?php echo esc_attr( $name ); ?>" |
| 43 | value="<?php echo esc_attr( $default_value ); ?>" |
| 44 | class="jet-form-builder__calculated-field-input jet-form-builder__field" |
| 45 | data-field-name="<?php echo esc_attr( $args['name'] ); ?>" /> |
| 46 | <div class="jet-form-builder__calculated-field-val"><?php echo wp_kses_post( $this->render_editor_placeholder() ); ?></div> |
| 47 | <?php if ( false !== $suffix ) : ?> |
| 48 | <div class="jet-form-builder__calculated-field-suffix"><?php echo wp_kses_post( $suffix ); ?></div> |
| 49 | <?php endif; ?> |
| 50 | </div> |
| 51 | <?php // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped |
| 52 |