Dear Thomas!
I have tried using your code but it doesn't seem to be working. Do you know what could be an issue?
Thank you for your help.
Kind regards,
Georgia
<script>
$( ( ) => {
/*
set store product detail named form labeled text field character max
length
Version : 0.2d0
SS Versions : 7.0, 7.1
v7.0 Templates : Brine ( Aria, Blend, Burke, Cacao, Clay, Fairfield,
Feed, Foster, Greenwich, Hatch, Heights, Hunter, Hyde,
Impact, Jaunt, Juke, Keene, Kin, Lincoln, Maple, Margot,
Marta, Mentor, Mercer, Miller, Mojave, Moksha, Motto,
Nueva, Pedro, Pursuit, Rally, Rover, Royce, Sofia,
Sonora, Stella, Thorne, Vow, Wav, West )
your template is not listed? then it is not currently
supported
Dependancies : jQuery
twcsl
Notes : this code is for forms added as part of the product
editor :
Classic Editor > Form or
New Editor > Customize > Custom Forms
it is not for forms added through :
Classic Editor > Additional Info or
New Editor > Customize > Additional Info
a text form field is either a text or text area field
By : Thomas Creedon < http://www.tomsWeb.consulting/ >
*/
/* for formName copy the value from the form editor Form Name field. you
only need exactly what can be selected from the field */
const formName = 'Gift message';
const maxLength = 80;
/* for formFieldLabel copy the value from the form Text Area field editor
LABEL field. you only need exactly what can be selected from the field */
const formFieldLabel = 'Gift message';
// do not change anything below, there be the borg here
if ( ! twcsl.storePage.isDetail ) return; // bail if not detail
// bail if no mutation observer available
if ( ! ( 'MutationObserver' in window ) ) return;
// begin get form field text labeled
var getFormFieldTextLabeled = ( label, $form ) => {
let $it = undefined;
$( '.text, .textarea', $form ).each ( function ( ) {
const $this = $( this );
const title = twcsl.getFormFieldLabel ( $this );
if ( title != label ) return true; // continue if not our field
$it = $( 'input, textarea', $this );
return false;
} );
return $it;
}
// end get form field text labeled
const observer = new MutationObserver ( function ( mutations ) {
$.each ( mutations, function ( ) {
if ( ! this.addedNodes.length ) return;
let $element = $( this.addedNodes [ 0 ] );
if ( ! $element.hasClass ( 'sqs-modal-lightbox' ) ) return;
if ( $( '.form-title', $element ).text ( ) != formName ) return;
const $form = $( 'form', $element );
const $text = getFormFieldTextLabeled ( formFieldLabel, $form );
if ( $text === undefined ) return true; // continue if no element
$text.attr ( 'maxLength', maxLength );
} );
} );
// start listening for changes in body
observer.observe ( document.body, { childList : true } );
} );
</script>