-
Notifications
You must be signed in to change notification settings - Fork 825
Forms: Include HTML id in Feedback classes #44760
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
Open
edanzer
wants to merge
12
commits into
trunk
Choose a base branch
from
add/forms-feedback-field-id
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+139
−19
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f488569
Forms: Add id to Feedback classes
edanzer a461c22
changelog
edanzer 81c538a
Make form_field_id a main property of Feedback_Field
edanzer 671f7a7
Remove unneeded paramters
edanzer 44ef20d
Simplify new Feedback methods
edanzer 9787ed5
Update tests
edanzer f384f70
Add Feedback tests
edanzer 26eba02
Update method names
edanzer 5974f1c
Add saved post test
edanzer bfba5ce
Default form_field_id to empty string
edanzer a777c96
Fix tests
edanzer 0aedac7
Undo fix for failing tests on trunk
edanzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/forms/changelog/add-forms-feedback-field-id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Forms: Preserve html ids when processing feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1983,4 +1983,51 @@ public function test_validate_radio_form() { | |
|
|
||
| Contact_Form::reset_errors(); | ||
| } | ||
|
|
||
| public function test_get_field_by_id_and_value_by_id_new_submission() { | ||
| $form_id = Utility::get_form_id(); | ||
| $_post_data = Utility::get_post_request( | ||
| array( | ||
| 'name' => 'John Doe', | ||
| 'email' => '[email protected]', | ||
| 'message' => 'Hello!', | ||
| ), | ||
| 'g' . $form_id | ||
| ); | ||
|
|
||
| $form = new Contact_Form( | ||
| array( | ||
| 'title' => 'Test Form', | ||
| 'description' => 'This is a test form.', | ||
| ), | ||
| "[contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Message' type='textarea' required='1'/]" | ||
| ); | ||
|
|
||
| $response = Feedback::from_submission( $_post_data, $form ); | ||
| $field_ids = $form->get_field_ids(); | ||
| $email_id = $field_ids['email']; | ||
|
|
||
| $this->assertNotEmpty( $email_id ); | ||
| $this->assertEquals( '[email protected]', $response->get_field_value_by_form_field_id( $email_id ) ); | ||
|
|
||
| $field = $response->get_field_by_form_field_id( $email_id ); | ||
| $this->assertInstanceOf( Feedback_Field::class, $field ); | ||
| $this->assertEquals( $email_id, $field->get_form_field_id() ); | ||
edanzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Save and reload; ensure the field id and value persist correctly | ||
| $saved_post_id = $response->save(); | ||
| $saved_response = Feedback::get( $saved_post_id ); | ||
| $this->assertEquals( '[email protected]', $saved_response->get_field_value_by_form_field_id( $email_id ) ); | ||
| $saved_field = $saved_response->get_field_by_form_field_id( $email_id ); | ||
| $this->assertInstanceOf( Feedback_Field::class, $saved_field ); | ||
| $this->assertEquals( $email_id, $saved_field->get_form_field_id() ); | ||
| } | ||
|
|
||
| public function test_get_field_by_id_and_value_by_id_legacy() { | ||
| $post_id = Utility::create_legacy_feedback( array() ); | ||
| $response = Feedback::get( $post_id ); | ||
|
|
||
| $this->assertSame( '', $response->get_field_value_by_form_field_id( 'email' ) ); | ||
| $this->assertNull( $response->get_field_by_form_field_id( 'email' ) ); | ||
| } | ||
| } | ||
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-forms-feedback-field-id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: enhancement | ||
|
|
||
| Forms: Preserve html ids when processing feedback. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be good to check - [contact-field label='Name' type='name' required='1' id="foo" /]
And
that
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.
This is apparently not that simple. As written above, this will not pass. Our testing code (if not our production code) seems to be set up in a way where id=foo will be converted to something like gXXX-ID-foo. And then there's some kind of disconnect in the data. I'm having a hard time figuring out how to fix/resolve it in a non-artificial way.