PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Product Field - why can't I edit the validation message?

  1. wmboy
    Member

    From http://www.gravityhelp.com/documentation/page/Product ...

    Validation Message

    If you would like to override the default error validation for a field, enter it here. This message will be displayed if there is an error with this field when the user submits the form. This option is only available when the Drop Down or Multiple Choice field type is selected.

    Why can't you have a custom validation message if you've set it to a User Defined Price? I would like to modify the "This field is required" message.

    Posted 9 years ago on Saturday August 25, 2012 | Permalink
  2. I've asked the developers for their feedback on this one, why it is specifically set up this way. Thanks for your patience, as it's the weekend and outside our normal support hours.

    In the meantime, it's possible to change this message with jQuery if you like. There are just a few lines of code.

    See this form:
    http://gravity.chrishajer.com/change-validation-message-on-user-defined-price-product/

    Submit with nothing entered and the form will come back with two validation errors. The first one uses the default validation error message of "This field is required." The second field, the donation field (user-defined price), will come back with an error message of "You gotta give me something here." That is changed with the following code:

    Add this to your theme's functions.php

    [php]
    // change 142 here to your form ID
    add_action('gform_enqueue_scripts_142', 'enqueue_validation_message', 10, 2);
    function enqueue_validation_message($form, $is_ajax) {
            // enqueue the scroll to top script which is stored in the child theme /js/ subdirectory, and depends on jQuery
        wp_enqueue_script('validation_message', get_stylesheet_directory_uri() . '/js/validation-message.js', array('jquery'));
    }

    That code references a script in your theme (or child theme)'s "js" directory called validation-message.js. That file contains this code:

    [js]
    jQuery(document).ready(function($) {
            $('div.gform_wrapper div.gform_body li#field_142_2 div.validation_message').html('You gotta give me something here.');
    });

    You will need to change the #field_142_2 to the ID of the form field for which you want to have this validation message.

    If you have any questions implementing this, please let us know.

    Posted 9 years ago on Sunday August 26, 2012 | Permalink
  3. wmboy
    Member

    Thanks for your reply, I've added the code to the functions file and added the javscript file, it doesn't seem to work though...

    The form ID is 4 and the field ID is 9 so I added the following:

    add_action('gform_enqueue_scripts_4', 'enqueue_validation_message', 10, 2);
    function enqueue_validation_message($form, $is_ajax) {
            // enqueue the scroll to top script which is stored in the child theme /js/ subdirectory, and depends on jQuery
        wp_enqueue_script('validation_message', get_stylesheet_directory_uri() . '/js/validation-message.js', array('jquery'));
    }

    Created new file validation-message.js in new folder js/

    jQuery(document).ready(function($) {
            $('div.gform_wrapper div.gform_body li#field_4_9 div.validation_message').html('Please enter a valid amount here.');
    });

    Here's a link of the page...
    });

    Posted 9 years ago on Sunday August 26, 2012 | Permalink
  4. If you look at the source of that page: view-source: http://flyadriatic.co.nz/gift-voucher/

    The script is not being enqueued. We first need to make sure to get the script added to the page, and then we need to make sure it works. Right now, it's not being added to the page.

    Can you try embedding the form without AJAX and see if is enqueued then?

    Posted 9 years ago on Monday August 27, 2012 | Permalink
  5. Turns out the original problem was due to a bug and was unintentional. I have emailed @wmboy the latest version which includes a fix for this issue. If you are experiencing the same issue, please email chris@rocketgenius.com and I will send the same version to you. Please reference this topic in your email. Thank you.

    Posted 9 years ago on Monday August 27, 2012 | Permalink
  6. wmboy
    Member

    Thanks for your help Chris.

    Posted 9 years ago on Monday August 27, 2012 | Permalink
  7. You're welcome.

    Posted 9 years ago on Tuesday August 28, 2012 | Permalink

This topic has been resolved and has been closed to new replies.