Skip to content

Commit c368dcb

Browse files
authored
Forms: Fix terms consent label colon issue (#45509)
* Remove period from labels on submission The Terms consent block has a period in its label and when we render the form submission we add a colon at the end which then renders as `.:`. I'm trimming the period at the end before inserting the colon.` * changelog * Fix Terms consent period colon issue frontend side Fix it also in the frontend for the ajax success response case.
1 parent 70757f7 commit c368dcb

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Forms: strip period from Terms submission label on the post-submission page.

projects/packages/forms/src/contact-form/class-contact-form.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,8 @@ function ( $json_str ) {
26002600
*/
26012601
private static function maybe_add_colon_to_label( $label ) {
26022602
$formatted_label = $label ? $label : '';
2603-
$formatted_label = str_ends_with( $formatted_label, '?' ) ? $formatted_label : rtrim( $formatted_label, ':' ) . ':';
2603+
// Special case for the Terms consent field block which a period after the label.
2604+
$formatted_label = str_ends_with( $formatted_label, '?' ) ? $formatted_label : rtrim( $formatted_label, ':.' ) . ':';
26042605

26052606
return $formatted_label;
26062607
}

projects/packages/forms/src/modules/form/view.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ const maybeAddColonToLabel = label => {
103103
if ( ! formattedLabel ) {
104104
return null;
105105
}
106-
107-
return formattedLabel.endsWith( '?' ) ? formattedLabel : formattedLabel.replace( /:$/, '' ) + ':';
106+
// Special case for the Terms consent field block which has a period at the end of the text.
107+
return formattedLabel.endsWith( '?' )
108+
? formattedLabel
109+
: formattedLabel.replace( /[.:]$/, '' ) + ':';
108110
};
109111

110112
const maybeTransformValue = value => {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: other
3+
4+
Forms: strip period from Terms submission label on the post-submission page.

0 commit comments

Comments
 (0)