Skip to content

FileUploadEditor Confirmation

Victor Tomaili edited this page May 3, 2021 · 1 revision

Requirements:

  • If uploader has no file selected, don’t show confirmation box

  • If we selected files, we want to choose difference files then it should show confirmation box with message:

    This will overwrite the current file. Are you sure you want to continue?

Demo:

Code:

constructor() {
  super();

  let sdsAddFileBtn = this.form.Sds.element.find(".add-file-button");

  let sdsClickEvt = (e) => {
      e.preventDefault();

      if (Q.trimToNull(Serenity.EditorUtils.getValue(this.form.Sds)) !== null) {
          Q.confirm("This will overwrite the current file. Are you sure you want to continue?", () => {
              $(e.target).click();

              sdsAddFileBtn.one('click', (e) => sdsClickEvt(e));
          }, { onCancel: () => sdsAddFileBtn.one('click', (e) => sdsClickEvt(e)) });
      }
      else {

          $(e.target).click();                    
          sdsAddFileBtn.one('click', (e) => sdsClickEvt(e));
      }
  };
  sdsAddFileBtn.one('click', (e) => sdsClickEvt(e));
}

Author: @minhhungit at https://minhhungit.github.io/2019/09/21/serenity-file-upload-editor-confirmation/

Clone this wiki locally