Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically adding new custom file inputs and reinitializing leads to wrong default texts #52

Open
daveekr opened this issue Jul 20, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@daveekr
Copy link

daveekr commented Jul 20, 2019

Hey folks,

I experienced following behavior in my web app:
So my page has one custom file input per default. However if a file is selected, a new custom file input is appended to the form, hence bsCustomFileInput needs to be reinitialized in order to get the recently added file inputs to work. I tried both bsCustomFileInput.init() and bsCustomFileInput.init(<field.selector>), both lead to wrong default texts as the second initialization sets the currently selected filename as the default text and overrides the actual default value for ALL custom file inputs. Eg:

input1.files = [] (default: "Choose file")
= user input ("file1.txt") =>
input1.files = ["file1.txt"] (default: "Choose file")
input2.files = [] (default: "Choose file", NOT initialized yet)
= bsCustomFileInput.init() or bsCustumFileInput.init(<input1.selector>) =>
input1.files = ["file1.txt"] (default: "file1.txt")
input2.files = [] (default: "Choose file")

Unfortunately I do not see any kind of quick workaround for this particular problem, so I think I am going for my own solution for now.

For a future release I think it would be nice to have a function to add new custom file inputs to the document or reinitialize the inputs without losing currently not used default values.

@Johann-S
Copy link
Owner

Hi @g0rill4z is it possible for you to create a live example of your issue via CodePen/JS Bin or Stackblitz and report back with your link ?

It'll help me to fix that 👍

@Johann-S Johann-S added the bug Something isn't working label Jul 23, 2019
@DevelopFaster
Copy link

DevelopFaster commented Jan 24, 2020

Not a bug
First, init you need to use

bsCustomFileInput.init()

In method (add new element)

bsCustomFileInput.destroy();
bsCustomFileInput.init();

@alstr
Copy link

alstr commented Jun 17, 2020

Not a bug
First, init you need to use

bsCustomFileInput.init()

In method (add new element)

bsCustomFileInput.destroy();
bsCustomFileInput.init();

This only worked for me if I called destroy before adding a new element and init after.

If I called it after cloning the input and clearing the value, the text remained the same as the original input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants