I have been created a component with a form and a file uploader.
I need to modify a typescript variable to disabled a "Done" button. I mean, i need to prevent that my form will submit before the upload has done.
code:
(follow the uploading variable)
import { Component, OnInit} from '@angular/core';
declare var $: any;
@Component({
selector: 'app-child-add-moment',
templateUrl: './child-add-moment.component.html',
styleUrls: ['./child-add-moment.component.css']
})
export class ChildAddMomentComponent implements OnInit {
private FILE_UPLOAD_URL = 'http://localhost/uploader/ajax_upload_file.php';
uploading = false;
uploadedFiles = 0; // I need change this variable from $('#filer_input2') success function
constructor() { }
ngOnInit() {
this.initializeUploader();
}
initializeUploader(): void {
$('#filer_input2').filer({
changeInput: '<a class="btn btn-primary">Add photo</a>',
showThumbs: true,
theme: 'dragdropbox',
templates: {
box: '<ul class="jFiler-items-list jFiler-items-grid"></ul>',
item: '<li class="jFiler-item">{{fi-name}}</li>',
itemAppend: '<li class="jFiler-item">{{fi-name}}</li>',
progressBar: '<div class="bar"></div>',
itemAppendToEnd: false,
canvasImage: true,
removeConfirmation: true,
_selectors: {
list: '.jFiler-items-list',
item: '.jFiler-item',
progressBar: '.bar',
remove: '.jFiler-item-trash-action'
}
},
uploadFile: {
url: this.FILE_UPLOAD_URL,
data: null,
type: 'POST',
enctype: 'multipart/form-data',
synchron: true,
beforeSend: function() {
// This show FALSE value but this value is not from "uploading" var from the component.
console.log(this.uploading);
if (!this.uploading) {
this.uploadedFiles = 0;
}
// I set this variable to TRUE to DISABLE some buttos from my template. But this setter, dont change the value of the "uploading" variable from the component.
this.uploading = true;
},
success: function(data, itemEl, listEl, boxEl, newInputEl, inputEl, id)
{
this.uploadedFiles++;
const filerKit = inputEl.prop('jFiler');
filerKit.files_list[id].name = new_file_name;
if (filerKit.files_list.length === this.uploadedFiles) {
console.log('All files have been uploaded');
// When upload has been finished, I set this variable to FALSE to ENABLE some buttons again.
this.uploading = false;
this.uploadedFiles = 0;
}
},
error: null,
onComplete: null
},
dialogs: null,
captions: {
button: 'Choose Files',
feedback: '"Choose files To Upload',
feedback2: 'files were chosen',
drop: 'Drop file here to Upload',
removeConfirmation: '"Are you sure you want to remove this file?',
errors: null
}
});
}
How can I modify "uploading" variable from "beforeSend" and "success" functinos?
Something important: I want to bind my var "uploading" with the template.
It is for enable and disable a button:
<button type="button" class="btn btn-primary" [class.disabled]="uploading"> Add </button>
Thanks
this.loadingto done and in your htmlDonebutton condition put a condition like[hidden]="loading"