-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix forms input placeholder displaying when its value is "0" #42173
base: trunk
Are you sure you want to change the base?
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
552ff87
to
058a008
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1066,14 +1066,14 @@ public function render_field( $type, $id, $label, $value, $class, $placeholder, | |||
|
|||
$form_style = $this->get_form_style(); | |||
if ( ! empty( $form_style ) && $form_style !== 'default' ) { | |||
if ( empty( $placeholder ) ) { | |||
if ( '' === $placeholder ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit: I'm not very familiar with this code, but from the looks of it, it might be technically possible for $placeholder
to be null
.
I.e. it looks like the placeholder is set here, which gets retrieved from the shortcode via get_attribute, which falls back to null
.
In that case, would it be safer to check for ! isset( $placeholder ) || '' === $placeholder
? Though in practice, I haven't been able to break this in manual testing, so I might very well be overthinking it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point, maybe it would be safer to do that. What I don't get is the reason for this condition, as it seems we're just adding a space to $placeholder
if it's empty 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirmed and it's super weird that adding styles to the form to trigger that condition means any field without a placeholder suddenly acquires placeholder=" "
:

This feels like a mistake. CC @simison in case you have any context on this?
Fixes #41725
Proposed changes:
empty()
to explicitly check if the string value is empty instead.Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: