Skip to content

Commit

Permalink
move save value manipulation to JS
Browse files Browse the repository at this point in the history
  • Loading branch information
ilicfilip committed Nov 5, 2024
1 parent fa8313f commit a36c90f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
20 changes: 20 additions & 0 deletions assets/js/settings-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ customElements.define(
this.select_page = this.querySelector( 'select' );
this.hidden_input = this.querySelector( 'input[type="hidden"]' );

// Update inputs on page load.
if ( '' !== this.hidden_input.value ) {
if ( '_no_page_needed' === this.hidden_input.value ) {
this.radio_buttons.forEach( ( radio ) => {
if ( radio.value === 'not-applicable' ) {
radio.checked = true;
}
} );
} else {
// Value is a number.
this.radio_buttons.forEach( ( radio ) => {
if ( radio.value === 'yes' ) {
radio.checked = true;
}
} );

this.select_page.value = this.hidden_input.value;
}
}

// Update hidden input on change.
this.radio_buttons.forEach( ( radio ) =>
radio.addEventListener(
Expand Down
7 changes: 1 addition & 6 deletions views/setting/page-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@

$prpl_setting_value = isset( $prpl_setting['value'] ) ? $prpl_setting['value'] : '';

// Default values.
$prpl_select_value = 0;
$prpl_radio_value = 'no';
if ( '_no_page_needed' === $prpl_setting_value ) {
$prpl_radio_value = 'not-applicable';
} elseif ( is_numeric( $prpl_setting_value ) && 0 < $prpl_setting_value ) {
$prpl_radio_value = 'yes';
$prpl_select_value = (int) $prpl_setting_value;
}
?>
<prpl-page-select>
<div class="item-description">
Expand Down

0 comments on commit a36c90f

Please sign in to comment.