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

File upload #172

Closed
fizerkhan opened this issue Mar 29, 2017 · 19 comments
Closed

File upload #172

fizerkhan opened this issue Mar 29, 2017 · 19 comments

Comments

@fizerkhan
Copy link

I want to upload CSV file. What is the input type for file upload?

@cristijora
Copy link
Collaborator

I don't see file upload being handled in the code. You can go with your own custom component and use any of the exisiting file upload components that are out there (e.g here )

cristijora pushed a commit to cristijora/vue-form-generator that referenced this issue Mar 29, 2017
icebob added a commit that referenced this issue Mar 29, 2017
@fizerkhan
Copy link
Author

@cristijora Your commit will fix the issue right?

@cristijora
Copy link
Collaborator

Yes, the PR got merged and it will be available in the next build or if you need it now simply use the js from here

@fizerkhan
Copy link
Author

@cristijora Thanks. 👍

@fizerkhan
Copy link
Author

fizerkhan commented Mar 29, 2017

@cristijora I got this error after integrating this js changes

DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
    at Array.updateDOMProps (http://localhost:3000/app/app.js:10043:19)
    at patchVnode (http://localhost:3000/app/app.js:9559:62)
    at updateChildren (http://localhost:3000/app/app.js:9480:9)
    at patchVnode (http://localhost:3000/app/app.js:9564:29)
    at VueComponent.patch [as __patch__] (http://localhost:3000/app/app.js:9689:9)
    at VueComponent.Vue._update (http://localhost:3000/app/app.js:7663:19)
    at VueComponent.<anonymous> (http://localhost:3000/app/app.js:7630:10)
    at Watcher.get (http://localhost:3000/app/app.js:6827:27)
    at Watcher.run (http://localhost:3000/app/app.js:6896:22)
    at flushSchedulerQueue (http://localhost:3000/app/app.js:6710:13)
logError @ app.js:5601

@cristijora
Copy link
Collaborator

I will look into it.

@cristijora
Copy link
Collaborator

@fizerkhan Try not to set the initial model value for the file input to an empty string. Does this appear every time you upload something or only initially?

@fizerkhan
Copy link
Author

fizerkhan commented Mar 30, 2017

@cristijora It happens only after I select a file from the file dialog.

I did not set any initial value to the model. My schema look like

{
    type: "input",
    inputType: "file",
    label: "Select a CSV",
    model: "file",
    featured: true
},

I created model like

this.model = schemaUtils.createDefaultObject(this.importProspectSchema);

@fizerkhan
Copy link
Author

fizerkhan commented Mar 30, 2017

@cristijora It fixed by setting file value to ''.

this.model.file = '';

I really don't how it works. but it works.

@BramVer
Copy link

BramVer commented Apr 12, 2017

Is anyone still looking into this? Just wanted to bump the thread, since I'm experiencing the same annoyance.
Fizerkhan's fix didn't solve it for me, whether I put the initial value to null or an empty string.

The solution works, and files get transferred flawlessly, only the warning is something I'd like to omit in my final product.

@icebob
Copy link
Member

icebob commented Apr 12, 2017

What kind of warning?

@BramVer
Copy link

BramVer commented Apr 12, 2017

@icebob The same warning fizerkhan received. It's a DOMException, but nothing crashes and the file selection works all the same.

image

In my model I tried setting initial value to an empty string and null, but that doesn't make any difference.
My schema looks like this:

          {
            //ATTACHMENT
            type: "input",
            inputType: "file",
            model: "attachments",
            label: "Attachment",
            files: true,
            multiple: true,

            styleClasses: 'col-md-6',
          },

It happens right after you confirm which file to upload in the popup window.

@fizerkhan
Copy link
Author

fizerkhan commented Apr 12, 2017

@BramVer Can you please set the value as empty string '' for other input fields in the form?

@BramVer
Copy link

BramVer commented Apr 12, 2017

@fizerkhan You meant setting all values in the model to an empty string, right?

That doesn't do it for me sadly, besides getting the same warning, other input fields dont work because they're not initialized of course.

I see that you manually set this.model.file to an empty string, can I ask where you did this? I tried manually setting that in 'created' as well, but does nothing.

@fizerkhan
Copy link
Author

fizerkhan commented Apr 13, 2017

@BramVer I did like this

// HTML
<vue-form-generator :schema='schema' :model='model' ref='form'></vue-form-generator>

and

// Javascript
this.model = schemaUtils.createDefaultObject(mySchema);
this.model.file = '';
this.model.content = '';

Even after setting this.model.file = '';, I got the same warning for content input. So I set it to empty too.

@BramVer
Copy link

BramVer commented Apr 13, 2017

@fizerkhan This removed the warning, thank you.

Instead of doing this (which is more in line with the structure of the code):

      name: '...',

      model: {
        start_date: moment(),
        end_date: moment().add(1, 'days'),
        description: "",
        leave_type: null,
        attachments: null,
      },

      schema: { ... }

I now do this:

  created: function() {
    this.model = VueFormGenerator.schema.createDefaultObject(this.schema);

    this.model.start_date = moment();
    this.model.end_date = moment().add(1, 'days');
    this.model.attachments = '';
  },

I still don't think this should be seen as a permanent solution, but more as a workaround,
since it doesn't fit well with the flow of the remaining code.
If there're no plans on improving this, perhaps mention this issue in the docs as a workaround.

@fizerkhan
Copy link
Author

@BramVer Great.
I agree with you that it is definitely a Work ground. It must be fixed or documented somewhere else.

@cristijora
Copy link
Collaborator

cristijora commented Jun 20, 2017 via email

@icebob
Copy link
Member

icebob commented Oct 20, 2017

Released in v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants