• Hi,

    Tested in Chrome and Firefox, a javascript error is raised when the plugin tries to set the placeholder on an element without ID, e.g. input type=”hidden”.

    I have created a little patch for this.

    --- a/gravity-forms-auto-placeholders/gravity-forms-auto-placeholders.php
    +++ b/gravity-forms-auto-placeholders/gravity-forms-auto-placeholders.php
    @@ -86,6 +86,9 @@ jQuery(document).ready(function($){
                    }
            ?>
            $.each($('.<?php echo $gfap_class; ?> input, .<?php echo $gfap_class; ?> textarea'), function () {
    +               if (!this.id) {
    +                       return;
    +               }
                    var gfapId = this.id;
                    var gfapLabel = $('label[for=' + gfapId + ']');
                    $(gfapLabel).hide();

    https://www.ads-software.com/plugins/gravity-forms-auto-placeholders/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter EXED internet

    (@exed-internet)

    Hi,

    I had to change my patch, since hidden inputs are not the only fields without a html5 placeholder area.
    https://html.spec.whatwg.org/multipage/forms.html#the-input-element

    I’ve tried to find another solution (found some solutions using “‘placeholder’ in element”) but they didn’t work.

    So for the new patch:

    --- a/gravity-forms-auto-placeholders/gravity-forms-auto-placeholders.php
    +++ b/gravity-forms-auto-placeholders/gravity-forms-auto-placeholders.php
    @@ -86,6 +86,9 @@ jQuery(document).ready(function($){
                    }
            ?>
            $.each($('.<?php echo $gfap_class; ?> input, .<?php echo $gfap_class; ?> textarea'), function () {
    +               if (type == 'hidden' || type == 'file' || type == 'radio' || type == 'checkbox' || type == 'color' || type == 'date' || type == 'range' || type == 'month' || type == 'week' || type == 'time' || type == 'datetime-local') {
    +                       return;
    +               }
    +               if (!this.id) {
    +                       return;
    +               }
                    var gfapId = this.id;
                    var gfapLabel = $('label[for=' + gfapId + ']');
                    $(gfapLabel).hide();

    Hi,

    another quick way to resolve this is to change line 90 from

    var gfapLabel = $(‘label[for=’ + gfapId + ‘]’);

    to

    var gfapLabel = $(‘label[for=”‘ + gfapId + ‘”]’);

    ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Javascript error on hidden form elements without ID’ is closed to new replies.