javascript - How to maintain state of file field in ExtJs -


i have file upload control using uploading image file on server. in operation going submitting form 2 times. issue after submitting form first time file upload filed giving value null @ second submit. lets see code below.

this.userphoto = new ext.create('ext.form.field.file', {         xtype: 'filefield',         padding: '5 5 5',         cls: 'p-photo-upload',         emptytext: 'photo',         buttononly: true,         fieldlabel: fleet.language.get('_fleet_user_userdetail_photo_'),         name: 'photo',         labelwidth: 200,         width: '26%',         msgtarget: 'under',         listeners: {             scope: this,              change: function (t, value) {                 var data = {};                 data.userphoto = t.value;                 data.imagetype = 'userphoto';                 var postdata = ext.encode(data);                 postdata = base64.encode(postdata);                 this.userdetailform.getform().submit({                     scope: this,                     url: fleet_proxy_url + 'index.php?c=user&a=uploadphoto',                     params: { postdata: postdata },                     success: function (form, action) {                         this.setloading(false);                         var b = ext.decode(action.response.responsetext);                         console.log(b);                         if (b && b.data && b.success === "s") {                             var img = '<img src="' + fleet_server_url + 'images/temporary/' + b.data.photoname + '" />';                             this.userimage.setvalue(img);                         } else {                             this.userdetailform.getform().findfield('photo').markinvalid(fleet.language.get(b.errors[0].photo));                         }                     }                 });             }          }     }); 

this.userphoto object of ext.form.field.file, after browse file uploading submitting form (you can see code in listeners change event of this.userphoto) form submit method used save temporary file @ server side. next going save same file , other user details on second submit, on second submit got nothing this.userphoto. please see below screen shot can better idea this. enter image description here

in image can see there browse , save button first form submit method done on after select file , second on save button click.

the sencha file upload field cannot retain state because underlying html field file upload field not intended keep state across form submission.

there many drawbacks when using file upload fields in forms, have switched different approach image upload.

in app, image uploads required, file upload field not connected actual form, submitted on own, , backend returns data url of image client. client puts data url hiddenfield in form. xtype:'image', bound hidden field, displays content of hidden field (= image) in frontend.

that way,

  • the data url can more handled in database because "readable" string, not blob,
  • the data url loaded , saved other data in form,
  • the data url can loaded , saved infinitely often,
  • i need 1 backend endpoint handles image uploads, , can work data urls (strings) there on,
  • all forms can submitted json (a file upload field enforces standard submission, when file upload field added existing form, have throw away backend code have endpoint).

the main drawback image goes on wire more simple file upload, @ least me, minor issue.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -