简体   繁体   English

切换禁用纸张按钮的属性

[英]Toggle disabled attribute of paper-button

I have a paper-button (send button) which is related to multiple paper-input fields/element. 我有一个paper-button (发送按钮),它与多个paper-input字段/元素相关。 The paper-input button should be disabled as long as the user fills out all related paper-input fields/elements ( newEmail and passwd ). 只要用户填写所有相关的paper-input字段/元素( newEmailpasswd ),就应禁用paper-input按钮。

This is the important part of the element 这是元素的重要部分

  <gold-email-input id="newEmail"
                    label="Email"
                    no-label-float required>
  </gold-email-input>

  <paper-input id="passwd"
               type="password"
               label="Password"
               no-label-float required>
  </paper-input>

  <div class="buttons">
    <paper-button dialog-dismiss>Cancel</paper-button>
    <paper-button dialog-confirm autofocus
                  disabled$="[[isInputEmpty($$.newEmail.value, $$.passwd.value)]]"
                  on-tap="changeEmail"
                  class="default">Save</paper-button>
  </div>

The function disabled$="[[isInputEmpty($$.newEmail.value, $$.passwd.value)]]" won't be called when the newEmail.value or passdw.value change. 当newEmail.value或passdw.value更改时,将禁用函数disabled $ =“[[isInputEmpty($$ .newEmail.value,$$。passwd.value)]]”

This is the JavaScript part: 这是JavaScript的一部分:

  isInputEmpty (email, pass) {
    if (email.length === 0 || pass.length === 0) return true;
    return false;
  }

What's the correct implementation to toggle the attribute disabled between true and false ? 什么是正确的实现切换真假 禁用的属性?

  1. disabled is actually a property of <paper-button> (not an attribute), so you should not be using the attribute-binding syntax (ie, $= ). disabled实际上是<paper-button> (不是属性)的属性,因此您应该使用属性绑定语法 (即$= )。

     <!-- don't do this --> <!-- <paper-button disabled$="[[isInputEmpty(...)]]"> --> <paper-button disabled="[[isInputEmpty(...)]]"> 
  2. You're attempting to pass the values of newEmail and passwd in your binding, but you're not using the correct syntax. 您试图在绑定中传递newEmailpasswd的值,但是您没有使用正确的语法。 You'll have to bind the values from those inputs into properties that you would pass as arguments in your computed binding: 您必须将这些输入中的值绑定到您将作为计算绑定中的参数传递的属性:

     <gold-email-input value="{{email}}"></gold-email-input> <paper-input value="{{password}}"></paper-input> <paper-button disabled="[[isInputEmpty(email, password)]]"></paper-button> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM