dynamically causing file browser to appear

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • walter-google@easypeas.net

    dynamically causing file browser to appear

    Hi,

    I need to capture an event on a form file input button and present a
    dialog before allowing the user to browse for a file. (A customer
    needs this in a CMS that I'm customizing for them.) Capturing the
    click is easy:
    <form>
    <input type="file" id="theButton" />
    </form>

    function theFunction() {
    // do something
    return false;
    }

    document.getEle mentById("theBu tton").onclick = theFunction;

    The function presents a TOU in a div; when the user clicks "I Agree"
    the browse dialog should appear. Everything works but forcing the
    browse dialog to appear after accepting. I assumed something like

    document.getEle mentById("theBu tton").onclick = theOriginalFunc tion;
    document.getEle mentById("theBu tton").click();

    would work, but no dice. focus() doesn't work, either.

    Ideas? This needs to be cross-platform, but I'm developing on OS X w/
    Firefox 3.

    Thanks,

    Walter
  • David Mark

    #2
    Re: dynamically causing file browser to appear

    On Nov 1, 4:42 pm, walter-goo...@easypeas .net wrote:
    Hi,
    >
    I need to capture an event on a form file input button and present a
    dialog before allowing the user to browse for a file.  (A customer
    needs this in a CMS that I'm customizing for them.)  Capturing the
    click is easy:
    What is this dialog supposed to do? Why do you feel you need to
    present it just before the browser dialog?
    <form>
      <input type="file" id="theButton" />
    </form>
    Actually, that is not a button.
    >
    function theFunction() {
      // do something
    Showing a (non-standard) modal dialog is all you can do here. (FF3
    and IE4+ are the only agents I know of that support this.)
      return false;
    Return the appropriate value based on the result of the modal dialog.

    The showModal() method of the HTMLDialogElement interface displays the dialog as a modal dialog, over the top of any other dialogs or elements that might be visible.

    >
    }
    >
    document.getEle mentById("theBu tton").onclick = theFunction;
    The irritating thing about this is it breaks the accompanying
    textbox. My host's "control panel" application does this, but then
    they do a lot of stupid things.

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: dynamically causing file browser to appear

      David Mark wrote:
      On Nov 1, 4:42 pm, walter-goo...@easypeas .net wrote:
      >document.getEl ementById("theB utton").onclick = theFunction;
      >
      The irritating thing about this is it breaks the accompanying
      textbox. [...]
      Looks like with Fx3/Win it has been broken already. I find it a rather
      stupid default that a click on the accompanying textbox now works like a
      click on the button; it makes the attempt at seeing what the full selected
      filename is a PITA.


      PointedEars
      --
      var bugRiddenCrashP ronePieceOfJunk = (
      navigator.userA gent.indexOf('M SIE 5') != -1
      && navigator.userA gent.indexOf('M ac') != -1
      ) // Plone, register_functi on.js:16

      Comment

      • walter-google@easypeas.net

        #4
        Re: dynamically causing file browser to appear

        Thanks for your reply. At this point in development, I need to
        justify changing our customer's wishes with a good reason. For this
        reason, I'd like to know if it's possible to activate a file browse
        input activity dynamically or not.

        The customer is a national professional society, and requires that
        people posting documents (done via the form I'm working on) agree to
        their TOU. Their TOU statment is several paragraphs long; because of
        this and aesthetic reasons, we decided to go against the modal dialog.

        My research shows that overriding the browse button works in FF, IE
        and Safari; these are the only browsers we test against or guarantee,
        so if it doesn't work elsewhere, that's acceptable.

        Probably a better way to do it would be to wait for the submit and
        bring it there. A problem is that several documents can be attached
        simultaneously (using the same input field), meaning a person may
        browse for several documents and finally refuse the TOU, thus
        potentially pissing them off.

        Anyway, is the dynamic activation of a browse input possible? That's
        what I really need to know now.

        Thanks,

        Walter

        On Nov 1, 1:55 pm, David Mark <dmark.cins...@ gmail.comwrote:
        On Nov 1, 4:42 pm, walter-goo...@easypeas .net wrote:
        >
        Hi,
        >
        I need to capture an event on a form file input button and present a
        dialog before allowing the user to browse for a file.  (A customer
        needs this in a CMS that I'm customizing for them.)  Capturing the
        click is easy:
        >
        What is this dialog supposed to do?  Why do you feel you need to
        present it just before the browser dialog?
        >
        <form>
          <input type="file" id="theButton" />
        </form>
        >
        Actually, that is not a button.
        >
        >
        >
        function theFunction() {
          // do something
        >
        Showing a (non-standard) modal dialog is all you can do here.  (FF3
        and IE4+ are the only agents I know of that support this.)
        >
          return false;
        >
        Return the appropriate value based on the result of the modal dialog.
        >
        The showModal() method of the HTMLDialogElement interface displays the dialog as a modal dialog, over the top of any other dialogs or elements that might be visible.

        >
        >
        >
        }
        >
        document.getEle mentById("theBu tton").onclick = theFunction;
        >
        The irritating thing about this is it breaks the accompanying
        textbox.  My host's "control panel" application does this, but then
        they do a lot of stupid things.

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: dynamically causing file browser to appear

          walter-google@easypeas .net wrote:
          Thanks for your reply.
          Which reply?
          At this point in development, I need to justify changing our customer's
          wishes with a good reason. For this reason, I'd like to know if it's
          possible to activate a file browse input activity dynamically or not.
          It's not. Satisfied?
          The customer is a national professional society, [...]
          Entirely irrelevant.


          PointedEars
          --
          realism: HTML 4.01 Strict
          evangelism: XHTML 1.0 Strict
          madness: XHTML 1.1 as application/xhtml+xml
          -- Bjoern Hoehrmann

          Comment

          • David Mark

            #6
            Re: dynamically causing file browser to appear

            On Nov 2, 9:28 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
            wrote:
            David Mark wrote:
            On Nov 1, 4:42 pm, walter-goo...@easypeas .net wrote:
            document.getEle mentById("theBu tton").onclick = theFunction;
            >
            The irritating thing about this is it breaks the accompanying
            textbox.  [...]
            >
            Looks like with Fx3/Win it has been broken already.  I find it a rather
            Really? As in, you can't select the text in the textbox at all?
            Maybe it wasn't a bad script to blame after all (just a bad browser.)

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: dynamically causing file browser to appear

              David Mark wrote:
              Thomas 'PointedEars' Lahn wrote:
              >David Mark wrote:
              >>On Nov 1, 4:42 pm, walter-goo...@easypeas .net wrote:
              >>>document.get ElementById("th eButton").oncli ck = theFunction;
              >>The irritating thing about this is it breaks the accompanying
              >>textbox. [...]
              >Looks like with Fx3/Win it has been broken already. I find it a rather
              >
              Really? As in, you can't select the text in the textbox at all?
              You can select the text using a pointing device, but once you release the
              button over the control you get the file select dialog like when you just
              clicked anywhere within the control. In my "Mozilla/5.0 (Windows; U;
              Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3" at least;
              an extension might interfere, YMMV.
              Maybe it wasn't a bad script to blame after all (just a bad browser.)
              Maybe, although I would like to emphasize that this nasty little bug does
              not make Firefox a bad browser :)


              PointedEars
              --
              Prototype.js was written by people who don't know javascript for people
              who don't know javascript. People who don't know javascript are not
              the best source of advice on designing systems that use javascript.
              -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

              Comment

              Working...