ruzam has asked for the wisdom of the Perl Monks concerning the following question:

According to the cgi docs:
-tabindex Automatically add tab index attributes to each form field. With this option turned off, you can still add tab indexes manually by passing a -tabindex option to each field-generating method.
The problem is that I don't use -tabindex and I don't pass it into field-generating methods. Yet the generated html contains 'tabindex=' entries and they totally mess up the browser's normal tabbing. Is this a cgi bug or is there an undocumented (or newer) option I can use to turn off tabindex generation? As it is I'm having to regex the generated html to remove this feature.

Replies are listed 'Best First'.
Re: CGI.pm and tabindex
by dirving (Friar) on Aug 31, 2006 at 03:54 UTC

    A quick read of the CGI.pm source code shows that the tabindex behavior is controlled in two ways: by setting a CGI package global called $TABINDEX, and when you explicitly pass in a -tabindex for each element. The bizarre part is that $TABINDEX is false by default and only gets set to true if -tabindex is passed to the constructor.

    You may be able to turn off this behavior by setting $CGI::TABINDEX = 0 from your code, but it really isn't a good idea to muck around with a module's internals like that -- you're better off figuring out why this is happening.

    The only explanation for this unexpected behavior that I can think of is that you are using the CGI module in a persistent environment (mod_perl, FastCGI, SpeedyCGI or whatever) and one of your other scripts is using the global -tabindex option, which CGI.pm is failing to reset between invocations for whatever reason.

      but it really isn't a good idea to muck, around with a module's internals like that

      Unless you do it properly:

      local $CGI::TABINDEX = 0;
      Thanks. The persistent environment is a good lead, but in this case I don't believe it applies. I'll snoop around the CGI.pm source and see if a better explanation turns up. For now I've been passing -tabindex => '' into each element which effectively eliminates side effects from the browser, but is a pain in the back end. If I were a suspicious man I might suspect that Mandriva has taken some artistic license with the default behaviour of their packaged version. Or maybe it's just something simple that I've missed...
        Try the following one-liners on the command-line:
        perl -MCGI=:form, -e 'print textfield()'
        perl -MCGI=:form,:tabindex -e 'print textfield()'

        On my system, the first one outputs <input type="text" name="" /> without the tabindex while the second one includes the tabindex attribute: <input type="text" name="" tabindex="1"  />

        This is just a quick check if the defaults are for some reason different in your CGI.pm or whether there is something more mysterious going on. If your results from running these are the same as mine, then there must be something in your program or the environment it's running in that is triggering the strange tabindex behavior.

A reply falls below the community's threshold of quality. You may see it by logging in.