on change of html input form element does not work 2nd time if SAME input file...

10490
4
Jump to solution
08-18-2020 05:34 AM
MichaelLev
Occasional Contributor III

In my custom widget html I have:

    <buton class="esri-button">
        <form enctype="multipart/form-data" method="POST"
                 data-dojo-attach-point="uploadForm">
            <input type="file" name="file" accept=".zip,.rar,.7zip"
                      data-dojo-attach-point="inFile" />
        </form>
    </buton>

in my widget (startup or onOpen) I have:

on(this.uploadForm, "change", lang.hitch(this, function (event) {
    ...
}));

It works fine, but if I activates it second time on SAME input file, the code inside the "on" callback is not entered at all...

I assume it's since the "change" event has not occurred since it remembers the previous file.

Am I right?

Can I detect it and present a warning (either by html or by javascript)?

Help will be greatly appreciated,

Michael

0 Kudos
1 Solution

Accepted Solutions
HarishPalaniappan
New Contributor III

That is a javascript Question you have.. not really ESRI ArcGIS JS related. So you should review javascript topics to do the warning part. May be this below link will guide -> https://stackoverflow.com/questions/12030686/html-input-file-selection-event-not-firing-upon-selecti...

And if you have further questions on it.. you should post to stackoverflow javascript forum probably.

View solution in original post

4 Replies
HarishPalaniappan
New Contributor III

Hi Michael Lev, 

You are correct. Just ensure the event handler is not disabled or changed in any other part of your code. You seem to be programmatically attaching the onchange event, that’s why I say that.

 

You may need another button /mechanism to call a validation method. To check if the file path is changed and to produce your warning related logic.. as the code you have shared indicates only onChange handler.

Thank You!

0 Kudos
MichaelLev
Occasional Contributor III

Dear Harish Palaniappan‌,

Thank you for replying!

I don't know how to create warning if the user operates again on same file.

So what I did, since I don't want that if the user tries to act again on same file, nothing will happen without telling him the reason, so I always present text telling the user he can't operate again on same file unless clicking another "Clear" button to clear "inFile".

Please -

  1. Is there another handler I can use (except "change") that will activate the callback even on same last file again?
  2. Can you please tell me how to create warning if the user operates again on same file?

I'll appreciate your help, since I'm not so familiar with that area.

Michael

0 Kudos
HarishPalaniappan
New Contributor III

That is a javascript Question you have.. not really ESRI ArcGIS JS related. So you should review javascript topics to do the warning part. May be this below link will guide -> https://stackoverflow.com/questions/12030686/html-input-file-selection-event-not-firing-upon-selecti...

And if you have further questions on it.. you should post to stackoverflow javascript forum probably.

MichaelLev
Occasional Contributor III

Dear Harish Palaniappan‌,

Thank you very much!

Both for showing how to search solution for such cases, and for pointing to link that showed me the way to go - I just automatically cleared "inFile" value after each time I have completed handling it.

Michael

0 Kudos