【问题标题】:Remove File Upload and Cancel Button from Primefaces p:fileUpload从 Primefaces p:fileUpload 中删除文件上传和取消按钮
【发布时间】:2014-10-14 15:35:05
【问题描述】:

我想从 p:fileUpload 中删除上传和取消按钮。对于上传按钮,我尝试了这样的 css(不同的变体):

.ui-fileupload-upload button {
        display: none;
}

但它仍然可见。

<button type="button"
    class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-state-disabled ui-fileupload-upload"
    disabled="disabled">
    <span
        class="ui-button-icon-left ui-icon ui-c ui-icon-arrowreturnthick-1-n"></span>
    <span class="ui-button-text ui-c">Upload</span>
</button>

我看到了这个出版物 [a link] (how to remove upload cancel button from <p:fileUpload>) 并再次尝试了不同的 css,但我没有设法摆脱它。谢谢。

【问题讨论】:

  • 您忘记告诉所使用的 PrimeFaces 版本。
  • Primefaces,4.0 版

标签: css jsf file-upload primefaces


【解决方案1】:

PrimeFaces 6.x 或更新版本

至少使用这些属性:

<p:fileUpload ... auto="true" skinSimple="true" />

PrimeFaces 4.x / 5.x

您只能为此使用 CSS,因为它们删除了 showButtons 属性:

.ui-fileupload-buttonbar .ui-fileupload-upload {
    display: none;
}
.ui-fileupload-buttonbar .ui-fileupload-cancel {
    display: none;
}

注意 CSS 排序规则,另见How do I override default PrimeFaces CSS with custom styles?

PrimeFaces 3.x 或更早版本

至少使用这些属性:

<p:fileUpload ... auto="true" showButtons="false" />

【讨论】:

    【解决方案2】:

    试试这个:

    .ui-fileupload-buttonbar .ui-fileupload-upload {
        display: none;
    }
    .ui-fileupload-buttonbar .ui-fileupload-cancel {
        display: none;
    }
    

    【讨论】:

    • 为什么这比接受和赞成的答案更好
    • 问的问题不是关于所有按钮,而只是关于“上传”和“取消”按钮。 “我想从 p:fileUpload 中删除上传和取消按钮......”
    • BalusC 的回答要求将 showbuttons 设置为 false。但是在 primefaces 6 的情况下没有这样的属性。您的解决方案运行良好。
    【解决方案3】:

    在角度中,使用来自ng2-file-uploadFileUploader,在.html 中:

    <tr *ngFor="let item of uploader.queue let i = index">
        <td>
          <div *ngIf= "!uploader.queue[i].isUploaded">
           <button type="button" class="btn btn-success btn-xs" style="margin:2px" (click)="onSubmit(i,item,$event.target)" >
            <span class="glyphicon glyphicon-upload"></span> Upload
           </button>
          </div>
        </td>
     </tr>

    component.ts

        public index:number ;
        public onFileSelected() {
          this.uploader.queue[this.index].isUploaded=false; // initializing uploaded to false
        }
    
        public onSubmit(index:number){
          this.uploadService.uploadFile(this.csvJsonData).subscribe((responseData)=>{
          this.onSubmitresponse = responseData ;
          if(this.onSubmitresponse.status==201){
            this.uploader.queue[index].progress = 100;
            this.toastrService.success('The File has been uploaded successfully !',this.onSubmitresponse.status,{positionClass:'toast-bottom-center'});
    
            this.uploader.queue[index].isUploaded=true;// will hide the upload button
          }
         else this.toastrService.error(this.onSubmitresponse.errorMessage,this.onSubmitresponse.status,{positionClass:'toast-bottom-center'});
        });
    
      }
    

    【讨论】:

    • 这个问题是关于 PrimeFaces,而不是 PrimeNG
    猜你喜欢
    • 2012-09-21
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 2014-07-20
    • 1970-01-01
    相关资源
    最近更新 更多