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.

Edit form field manually with javascript

  1. Hello, how do I manually through javascript update a fields value so constraints are properly triggered?
    I am currently using jQuery("#field_x_y").val("value");

    My constraint is:
    Show if Imagefile_path is not undefined

    Where Imagefile_path is the hidden element (field_x_y) being set by the javascript and its default value is undefined

    Posted 11 years ago on Saturday June 29, 2013 | Permalink
  2. Richard Vav
    Administrator

    So the Gravity Forms conditional logic works by applying an onChange event to the input but when you use JavaScript to set the value of that input the onChange event isn't triggered but the good news is that you can trigger it by using the jQuery .change() method without any arguments like so

    jQuery("#input_23_4").val("10").change();
    Posted 11 years ago on Saturday June 29, 2013 | Permalink
  3. Sadly it does not work for me.

    $hiddenImageFieldID.val(f_data.path + f_data.file).change();

    I've also tried using

    .trigger("change")
    Posted 11 years ago on Saturday June 29, 2013 | Permalink
  4. Anyone have any idea why the conditional logic event isn't being updated properly when using richardvav's example?

    Posted 11 years ago on Monday July 1, 2013 | Permalink
  5. Richard Vav
    Administrator

    Can you post your full script or a link to see this live. Forgetting triggering the conditional logic for a moment, does your script successfully set the value on the input?

    Posted 11 years ago on Monday July 1, 2013 | Permalink
  6. It can be viewed at http://www.thislooksgreat.com/
    After you have uploaded an image the code is run at ~line 368 inline script.
    I've removed the trigger() code tho as it appeared to do nothing. If you press F5 after uploading an image the field that is supposed to be shown is visible. So the conditional logic works on a refresh.

    Posted 11 years ago on Tuesday July 2, 2013 | Permalink
  7. Richard Vav
    Administrator

    It's because you are using a hidden field which doesn't get an onChange event added to it, try this instead

    .trigger(gf_apply_rules(2, [6,16,17,18,19,20], true));

    the numbers inside the square brackets are the fields you have set the conditional logic on, I just copied them all but you can reduce it down to just the field or fields you want the conditional logic triggered on

    Posted 11 years ago on Tuesday July 2, 2013 | Permalink
  8. It appears to work. The field gets shown. I only now have to solve an error I get from calling the function inside trigger

    "Uncaught TypeError: Cannot convert null to object " in jquery.min.js line 5.

    Thanks for the gf_apply_rules function.

    Posted 11 years ago on Tuesday July 2, 2013 | Permalink
  9. Richard Vav
    Administrator

    It looks like you figured this out.

    Posted 11 years ago on Thursday July 4, 2013 | Permalink
  10. Yeah, I put a try catch around it, I couldn't figure out why the function threw an undefined jquery event which crashes the application. So it's not really solved, but fixed enough :)

    It threw 3 events in this order:
    gform_post_conditional_logic,
    change
    undefined (crashes jquery)

    Posted 11 years ago on Friday July 5, 2013 | Permalink

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