| 1 |
<?php |
| 2 |
/** |
| 3 |
* input[type="hidden"] template |
| 4 |
*/ |
| 5 |
|
| 6 |
$this->add_attribute( 'required', $this->block_type->get_required_val( $args ) ); |
| 7 |
$this->add_attribute( 'name', $this->block_type->get_field_name( $args['name'] ) ); |
| 8 |
$this->add_attribute( 'data-field-name', $args['name'] ); |
| 9 |
$this->add_attribute( 'id', $this->block_type->get_field_id( $args ) ); |
| 10 |
|
| 11 |
if ( ! empty( $args['switch_on_change'] ) ) { |
| 12 |
$this->add_attribute( 'data-switch', 1 ); |
| 13 |
} |
| 14 |
|
| 15 |
$placeholder = isset( $args['placeholder'] ) ? $args['placeholder'] : false; |
| 16 |
$default = isset( $args['default'] ) ? $args['default'] : false; |
| 17 |
|
| 18 |
$this->add_attribute( 'data-default-val', $default ); |
| 19 |
|
| 20 |
?> |
| 21 |
<div class="jet-form-builder__field-wrap"> |
| 22 |
<select class="jet-form-builder__field select-field"<?php $this->render_attributes_string(); ?>><?php |
| 23 |
|
| 24 |
if ( $placeholder ) { |
| 25 |
$selected_placeholder = ''; |
| 26 |
|
| 27 |
if ( ! $default ){ |
| 28 |
$selected_placeholder = 'selected'; |
| 29 |
} |
| 30 |
|
| 31 |
printf( '<option value="" %1$s>%2$s</option>', $selected_placeholder, $placeholder ); |
| 32 |
} |
| 33 |
|
| 34 |
if ( ! empty( $args['field_options'] ) ) { |
| 35 |
|
| 36 |
foreach ( $args['field_options'] as $value => $option ) { |
| 37 |
|
| 38 |
$selected = ''; |
| 39 |
$calc = ''; |
| 40 |
|
| 41 |
|
| 42 |
if ( is_array( $option ) ) { |
| 43 |
$val = isset( $option['value'] ) ? $option['value'] : $value; |
| 44 |
$label = isset( $option['label'] ) ? $option['label'] : $val; |
| 45 |
} else { |
| 46 |
$val = $value; |
| 47 |
$label = $option; |
| 48 |
} |
| 49 |
|
| 50 |
if ( $default ) { |
| 51 |
$selected = selected( $default, $val, false ); |
| 52 |
} |
| 53 |
|
| 54 |
if ( is_array( $option ) && isset( $option['calculate'] ) ) { |
| 55 |
$calc = ' data-calculate="' . $option['calculate'] . '"'; |
| 56 |
} |
| 57 |
|
| 58 |
printf( '<option value="%1$s" %3$s%4$s>%2$s</option>', $val, $label, $selected, $calc ); |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
?></select> |
| 65 |
<?php echo $this->maybe_render_error( $args ); ?> |
| 66 |
</div> |