Skip to content

Commit

Permalink
WF#91 - Resolved DT Key Select Option List Bug (#92)
Browse files Browse the repository at this point in the history
* Resolved dt key select option list bug

* Ensure not-set blank lines are consistent

* Support seeker_path none keys

* Generic alternative

* Additional none blank label checks

* Addressed closing parenthesis spacing

* Only add empty option if empty option does not already exist
  • Loading branch information
kodinkat committed Apr 26, 2024
1 parent 182fbf0 commit 4e0ba06
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions includes/post-type-active-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,20 @@ public function template_row_dt_field_multi( $unique_key, $data ) {
echo '<input type="text" name="'.esc_attr( $unique_key ).'[title]" value="'.esc_html( $data['title'] ).'" style="width:100%;" />';
}
if ( is_array( $data['labels'] ) ){

// Ensure key_selects starting with not-sets; are replaced with a newline character.
if ( ( $data['type'] === 'key_select' ) && !empty( $data['labels'] ) && empty( trim( $data['labels'][0] ) ) && !empty( $data['values'] ) && in_array( $data['values'][0], [ 'not-set', 'none' ] ) ) {
$data['labels'] = array_merge( [ "\r\n" ], array_slice( $data['labels'], 1 ) );
}

$data['labels'] = implode( "\r\n", $data['labels'] );
} elseif ( is_string( $data['labels'] ) && !empty( $data['values'] ) && in_array( $data['values'][0], [ 'not-set', 'none' ] ) && !empty( explode( PHP_EOL, $data['labels'] )[0] ) ) {

$labels = explode( PHP_EOL, $data['labels'] );
if ( ( count( $data['values'] ) === count( $labels ) ) && empty( trim( $labels[0] ) ) ) {
$breaks = ( substr( $data['labels'], 0, 2 ) === "\r\n" ) ? "\r\n" : "\r\n\r\n";
$data['labels'] = $breaks . $data['labels'];
}
}
?>
<hr>
Expand Down Expand Up @@ -2292,6 +2305,14 @@ public static function make_labels_array( string $labels ) {

public static function match_dt_field_labels_with_values( $labels, array $values ) : array {
if ( is_string( $labels ) ){
if ( isset( $values[0] ) && in_array( $values[0], [ 'not-set', 'none' ] ) && !empty( explode( PHP_EOL, $labels )[0] ) ) {

$labels_array = explode( PHP_EOL, $labels );
if ( ( count( $values ) === count( $labels_array ) ) && empty( trim( $labels_array[0] ) ) ) {
$breaks = ( substr( $labels, 0, 2 ) === "\r\n" ) ? '' : "\r\n";
$labels = $breaks . $labels;
}
}
$labels = self::make_labels_array( $labels );
}
if ( empty( $labels ) || empty( $values ) ) {
Expand Down
3 changes: 2 additions & 1 deletion includes/utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,8 @@ class="input-<?php echo esc_attr( $dt_webform_value['type'] ) ?>"
<?php echo esc_attr( $dt_webform_value['required'] == 'yes' ? 'required' : '' ) ?>
>
<?php
if ( isset( $dt_webform_value['selected'] ) && $dt_webform_value['selected'] === 'no' ) {
$not_set_selected = ( isset( $dt_webform_value['selected'] ) && $dt_webform_value['selected'] === 'no' );
if ( $not_set_selected && isset( $list[0]['value'] ) && !in_array( $list[0]['value'], [ 'not-set', 'none' ] ) ){
echo '<option></option>';
}
foreach ( $list as $item ) {
Expand Down

0 comments on commit 4e0ba06

Please sign in to comment.