vitmalina / w2ui

UI widgets for modern apps. Data table, forms, toolbars, sidebar, tabs, tooltips, popups. All under 120kb (gzipped).
http://w2ui.com
MIT License
2.67k stars 727 forks source link

How to set data for w2field with type="file" in w2form #2579

Open vinhpt2 opened 2 weeks ago

vinhpt2 commented 2 weeks ago

I worder how to set value for w2field with type="file" in a w2form. If I set a string or null or "" the w2field go to malfunction - can not interact any more. (.w2ui-field-helper.w2ui-list have width=0px)

elfwine commented 1 week ago

The following setup works for me. Hope this one can helps you.

let form = new w2form({
  name: 'testForm',
  fields: [
    { field: 'name', type: 'text', html: { label: 'Name' } },
    { field: 'inputFile', type: 'file', html: { label: 'Upload File' } }
  ]
});

let data = {
    name: 'Test Name',
    inputFile: [
       { 
          'name': 'test.jpg',
          'type': 'image/jpeg',
          'content': {btob data},
          'size': 19303
       }
   ]
};
form.record = data;