A
A
Alexander2020-10-06 10:37:02
JavaScript
Alexander, 2020-10-06 10:37:02

Because of what, after pressing the Cancel button of the file selection window, this window can no longer be called again?

Explain why after pressing the Cancel button when opening a file selection dialog box, this window can no longer be called up again.
5f7c1d7ec0953336360868.jpeg

The opening of the dialog box happens to me by clicking on the svg element whose id = nit-file-input visually looks like a paper clip.
5f7c1e3dbba7c753513622.jpeg

<div class="form__add-file-wrapper">
                      <div class="form__add-file add-file">
                          <label class="label">
                             <svg class="icon icon-add-file" id="init-file-input">
                                <use xlink:href="/local/img/icons/sprite.svg#add-file"></use>
                              </svg>
                          </label> 
    
                          <div class="form__files-wrapper" id="msg_block"></div>
                      </div> 
                  </div>


After selecting the file, I dynamically create the html file element in the createInputTypeFile method. The input file tag is created dynamically, otherwise adding a file will not work, you can also dynamically create a tag every time a new file is added.
$(document).on('click', '#feedback #init-file-input', function (event) {
            obj.inputField = obj.createInputTypeFile(inputFile);
 });

The createInputTypeFile method creates an html-element field of type file in it and this field emulates a click event
createInputTypeFile: function(inputFileNum) {
        console.log('createInputTypeFile');
        const feedback = document.querySelector('#feedback');
        const input = document.querySelector('#file-input');

        if(!feedback.contains(input)){
            const input = document.createElement('input');
                input.setAttribute('id', 'file-input');
                input.setAttribute('type', 'file');
                input.setAttribute('name', 'file[]');
                input.style = 'display: none';             
                feedback.appendChild(input);
                input.click(); // эмуляция события click
        }     
    }

I can't figure out why the file selection window doesn't reappear if I press the Cancel button, is it on the JS side or somewhere deeper in the Browser?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pashok Doom, 2020-10-06
@Benzin102

A mix of jQuery and jies.
You do not delete the input after cancellation, it is present in the form and
if(!feedback.contains(input)){
the check does not pass here and the input is not clicked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question