Skip to content

Fix select placeholder falsy comparison and add value attribute#859

Merged
superdav42 merged 1 commit intomainfrom
bugfix/select-placeholder-value-attribute
Apr 14, 2026
Merged

Fix select placeholder falsy comparison and add value attribute#859
superdav42 merged 1 commit intomainfrom
bugfix/select-placeholder-value-attribute

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #843 (by @commercial-hippie) — addresses the additional finding from CodeRabbit's review.

Two issues on the placeholder <option> in field-select.php:

  1. Missing value="" attribute — without it, the form submits the placeholder text as the value instead of an empty string
  2. Falsy comparison bugselected(! $field->value) treats any falsy value ("0", 0, null, "") as "no selection", so a legitimate option with value "0" would incorrectly show the placeholder as selected

Change

-<option <?php selected(! $field->value); ?> class="wu-opacity-75">
+<option value="" <?php selected('', (string) $field->value); ?> class="wu-opacity-75">

Uses the proper two-argument selected() comparison with explicit string cast, so the placeholder is only selected when the field value is genuinely empty.

The placeholder <option> used selected(! $field->value) which incorrectly
selected the placeholder when $field->value was a falsy but valid value
like '0'. Replace with two-argument selected('', (string) $field->value)
and add an explicit value="" attribute.

Follow-up to PR #843 — based on CodeRabbit review suggestion.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 minutes and 45 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 36 minutes and 45 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c1de925-3f95-445c-b5a9-1476a33e23c1

📥 Commits

Reviewing files that changed from the base of the PR and between 2b88eda and 9d0bf08.

📒 Files selected for processing (1)
  • views/checkout/fields/field-select.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/select-placeholder-value-attribute

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions
Copy link
Copy Markdown

Performance Test Results

Performance test results for 177463b are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 40 (-1 / -3% ) 37.78 MB 815.50 ms (-99.50 ms / -12% ) 180.00 ms (-4.50 ms / -3% ) 1080.00 ms 2060.00 ms 1965.55 ms 91.95 ms (-2.10 ms / -2% )
1 56 49.03 MB 961.50 ms (+49.50 ms / +5% ) 152.50 ms (+8.50 ms / +6% ) 1115.50 ms (+58.50 ms / +5% ) 2098.00 ms (+58.00 ms / +3% ) 2012.65 ms (+56.00 ms / +3% ) 82.55 ms

@superdav42 superdav42 merged commit 34a6a65 into main Apr 14, 2026
9 of 11 checks passed
@superdav42
Copy link
Copy Markdown
Collaborator Author

Summary

Follow-up to #843 (by @commercial-hippie) — addresses the additional finding from CodeRabbit's review.
Two issues on the placeholder <option> in field-select.php:

  1. Missing value="" attribute — without it, the form submits the placeholder text as the value instead of an empty string
  2. Falsy comparison bugselected(! $field->value) treats any falsy value ("0", 0, null, "") as "no selection", so a legitimate option with value "0" would incorrectly show the placeholder as selected

Change

-<option <?php selected(! $field->value); ?> class="wu-opacity-75">
+<option value="" <?php selected('', (string) $field->value); ?> class="wu-opacity-75">

Uses the proper two-argument selected() comparison with explicit string cast, so the placeholder is only selected when the field value is genuinely empty.


Merged via PR #859 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).


aidevops.sh v3.8.28 spent 8m on this as a headless bash routine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant