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.

Altering a number field's min and max range values

  1. ericcovarrubias

    I have a form that features a drop down with about 10 options in it. Based on the value of that drop down, a user then fills in 5 to 8 additional number fields. The concept is the drop down represents various categories that they receive a certification for and then the subsequent number fields represent the points/scores they earned in subcategories for that certification. For a majority of these subcategories (number fields) the labels and names are identical and the only difference is the rangeMax value.

    For example, if a user can select Option A or Option B from the dropdown, they will then be shown 6 number input fields. If Option A is selected, the 6 number fields can each have a value between 1 and 10, whereas if Option B is selected the range would be 1 and 20.

    To test this, I attempted to modify the rangeMax value like this while looping through the number fields (this is being done via gform_pre_render):

    $field['rangeMin'] = 1;
    $field['rangeMax'] = 1;
    echo $field['rangeMax'] . " - ";
    if(trim($project->rating_system) == "Option A") {
      $field['rangeMax'] = 10;
    } else {
      $field['rangeMax'] = 20;
    echo $field['rangeMax'] . "";

    If I echo out the rangeMax of the field before and then after the conditional, it appears to work as the output is "1 - 10" or "1 - 20" as I want. However, the instructions below the number fields don't reflect the change and also when I submit the form it throws validation errors that the input is out of range when rangeMax is set to 20 and I enter 15 for example.

    Am I missing something, possible a validation rule I need to tweak within the JS or do I need to take an additional step to "save" the change so it will override the default range values entered through the admin dashboard?

    I can't seem to find much of anything about this, and in total with the various options available in the drop down I would need to manually create well over 50 number fields many of which are duplicates just with a different rangeMax value. I'm hoping I can just use one set of number fields and then modify the rangeMax dynamically via PHP. Thanks in advance for any guidance and support and if you need any additional information just let me know.

    Posted 9 years ago on Friday January 25, 2013 | Permalink
  2. gform_pre_render is performed before the whole form is loaded. Conditional logic is applied after the form is loaded. I don't think you can use gform_pre_render to modify the form after the form is displayed, based on your conditional logic selections. You're going to need another approach.

    You could do this with two forms, making the conditional choice in form 1, then using the gform_pre_render in form 2, based on the choices made in form 1. You would have to pass the values from form 1 to form 2, then change the min and max as you're doing now.

    Posted 9 years ago on Wednesday January 30, 2013 | Permalink