January 2nd, 2014: Updated to fix tabindex issues with forms added via the Gravity Forms widget.
Stop! This method is no longer recommended.
For accessibility reasons, adjusting the tabindex for Gravity Forms should be avoided. Giving the form priority over other interactive content is detrimental to users that rely on keyboard navigation.
This is most common when loading a Gravity Form on a page which is loading a non-GF form (like the WordPress comment form). You’re typing away on your Gravity Form and tab to the next field. Awesome. Except the next field is a completely different form. This snippet sets the starting index of your Gravity Form inputs ridiculously high so such conflicts never happen again.
{Gist removed. This article has been deprecated.}
How do I install this snippet?
Easy peasy. Just copy and paste the code above into your theme's functions.php file.
How to I use this functionality?
This snippet is plug-n-play. No changes needed (unless you’re still seeing tabindex conflicts which is highly unlikely). If you are, just update the 1000
in the snippet to a higher number until the conflict disappears.
Hi!
Nice snippet of code, thanks!
If there are n>1 Gravity Forms on the same page, it might be useful to assign a different tabindex value to each of them. I achieved this by adding a line to the
if
block:function gform_tabindexer( $tab_index, $form = false ) { $starting_index = 1000; // if you need a higher tabindex, update this number if( $form ) { add_filter( ‘gform_tabindex_’ . $form[‘id’], ‘gform_tabindexer’ ); $starting_index *= min( $form[‘id’], 10 ); } return GFCommon::$tab_index >= $starting_index ? GFCommon::$tab_index : $starting_index; }
[updated snippet can be found on gist: https://gist.github.com/31b7e1a2d874dc41d4a6%5D
Cheers, Guido
Sorry David, the comment parser has mangled my code & link. This is the correct link for the snippet:
https://gist.github.com/31b7e1a2d874dc41d4a6
Hi Guido, thanks for sharing! In this case, the GFCommon::$tab_index is already global across all forms so you don’t need to do anything fancy to prevent tabindex conflicts when multiple Gravity Forms are on the same page.
Thank you David! You are right, It makes a lot of sense: Gravity Forms only needs a starting number for tabindex, and then it sorts it out automatically. Cool! I’ll revert my snippet to your original version :-)
Maybe this is a new feature since you originally posted this article, but I found that adding a tabindex specification to the shorcode worked … like this: [gravityform id="1" tabindex="1000"]
Hi Simon, nope. You can set the tabindex from the shortcode since the early days of Gravity Forms. The benefit of this method is that you don’t have to set it on each shortcode. It works automatically for every form. Install and forget about it. :)
Fixed tab order issues with 2 gravity forms on page. Thanks!
Awesome! Glad you found this useful. :)
Does this snippet also prevent tabbing jumping from one Gravity form to the next?
(If so, i can’t get it to work).
Thank you very much! Steve
Hi Steve, no, this snippet actually helps with tabbing from one field to the next by avoiding issues where other elements on the page might have a tabindex that breaks the visual sequence of fields.
Hey David,
Thank you for the fast response and the helpful information!
Steve
October 2015 – still working! Cheers.
Awesome, Nick. Thanks for confirming. :)
Perfect, thank you for this!
My pleasure, Jamie. :)
This worked like a charm, just a simple copy and paste! Thank you!
Awesome, happy to help! :)
Thank you from the Philippines! :)
Great, worked perfectly. I was trying to use this code (below) but it wasn’t really working for me.
Thanks a lot,
Neil
Great! It looks like your code was stripped out but I’m glad this solution worked for you.
Thanks for this. Worked first time like a charm. Excellent.
Glad to hear it, Huw!
Brilliant – works like a charm with no further futzing around! Rocket Genius should really integrate this into their code. Seems like a silly bug to not fix.
Glad it worked well for you. :)
You are a genius! Thanks for sharing this with everyone! :D
THanks buddy
Hi,
thank you for this fix! It is working perfectly! :)
Great! Glad you found this useful. :)
Thank you.
Thank you! It worked like a charm for my client.
Glad to hear it!
hi how we can add new field to GF like “Ranking field” here: https://docs.google.com/forms/d/1wQ_akvbspn6KEeyuato4PiJ1nkeaxjfLKAjxGLilL14/viewform