Skip to content

Commit

Permalink
Merge pull request #202 from BoldGrid/issue-37
Browse files Browse the repository at this point in the history
added asterisks to required fields on checkout
  • Loading branch information
jamesros161 authored Jun 2, 2020
2 parents 5e35da5 + 46f90cd commit 1b762cf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/assets/js/front-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ var BoldGrid = BoldGrid || {};

// Handle forms.
forms: function( hasFloat = false ) {
var wcCheckoutLabels,
wcRequiredLabels = [];
let selectors = '.comment-form-rating #rating, .widget_categories .postform, .quantity .qty';

if ( ! hasFloat ) {
Expand All @@ -180,6 +182,22 @@ var BoldGrid = BoldGrid || {};
);
}

wcCheckoutLabels = $( 'form[name=checkout] .woocommerce-input-wrapper label' );

wcCheckoutLabels.each( function() {
if ( ! $( this ).html().includes( '(optional)' ) ) {
wcRequiredLabels.push( this );
}
} );

wcRequiredLabels.forEach( function( requiredLabel ) {
var placeholder = $( requiredLabel ).parent().find( 'input' ).attr( 'placeholder' );
if ( ! $.contains( requiredLabel, $( 'abbr' ) ) ) {
$( requiredLabel ).append( '<abbr class="required" title="required"> *</abbr>' );
$( requiredLabel ).parent().find( 'input' ).attr( 'placeholder', placeholder + ' *' );
}
} );

/**
* Determine the neutral color and return className
* that should be applied to native select elements.
Expand Down

0 comments on commit 1b762cf

Please sign in to comment.