【问题标题】:How to disable upload button when there is no file selected in meteorjs?当meteorjs中没有选择文件时如何禁用上传按钮?
【发布时间】:2018-01-18 06:03:36
【问题描述】:

我试过 slideForm.$invalid ,但它不起作用。你能建议最好的方法吗?

      <form name="slideForm">
          <div class="aboutFile">
             <input type="file" name="file" fileread="vm.file" class="form-control" ng-model="vm.file">
                <div class="create-component--perma-bg">
                  <i class="fa fa-plus-square-o" aria-hidden="true"></i>
                   <span ng-if="!vm.file.name">Add File </span>
                   <span ng-if="vm.file.name">{{vm.file.name}}</span>
                </div>
            <button type="button" class="btn btn-info bgChangeBtnInfo" ng-
               click="vm.upload(vm.file)" ng-disabled="slideForm.$invalid"> 
                 Upload</button>
          </div>
      </form>

【问题讨论】:

  • 而不是做 slideform.$invalid ;你不能拿一个变量 ng-disabled="someVar" 然后最初它会是假的,因为文件可能没有被选中,但是当它被选中时,然后将它分配给 true
  • 我试过了,但还是不行
  • 你能试试 slideform.file.$invalid 吗?
  • 仍然无法以其他方式工作?
  • 一种简单的方法是正如我所说在控制器中创建一个变量,如 vm.someVar=false;在 html ng-disabled="someVar" 中,当您单击按钮时,请执行 someVar=true

标签: javascript angularjs meteor angular-meteor angularjs-ng-disabled


【解决方案1】:

我认为您必须像这样将其设为必填字段

<input type="file" name="file" fileread="vm.file" class="form-control" ng-model="vm.file" required>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-12-08
  • 1970-01-01
  • 1970-01-01
  • 2022-01-12
  • 2015-12-01
  • 1970-01-01
  • 2011-05-02
  • 1970-01-01
相关资源
最近更新 更多