2014-10-30 21 views
1

我有一個紙張輸入元素,並且我將一個變量綁定到元素的inputValue以便實時顯示用戶輸入。該字段是必需的,所以如果該字段爲空,則組件按預期顯示警告。聚合物綁定到inputValue並使驗證工作

當我清理變量時出現問題,在這種情況下驗證狀態不會更新。

下面的代碼:

<link rel="import" href="../polymer/polymer.html"> 
<link rel="import" href="../paper-input/paper-input.html"> 

<polymer-element name="slimy-coconut" attributes="invalid,inputValue"> 
    <template> 

    <paper-input required="true" invalid={{invalid}} inputValue={{inputValue}}></paper-input> 
    invalid: {{invalid}}<br> 
    inputValue: {{inputValue}}<br> 
    <button on-click="{{cleanInputValue}}">Clean inputValue</button> 
    </template> 
    <script> 
    Polymer('slimy-coconut', { 

     cleanInputValue: function(event, detail, sender) { 
     this.inputValue = ""; 

     } 
    }); 
    </script> 
</polymer-element> 
<slimy-coconut name="Ele Dev"></slimy-coconut> 

這裏正在運行的例子:https://ele.io/fedy2/slimy-coconut

我如何可以綁定到inputValue將做出驗證工作?

回答

1

可以紙張輸入的「無效」屬性設置爲false - http://jsbin.com/rowehehiga/1/edit?html,output

+0

當我嘗試它,TT採用按鈕兩次點擊實際復位無效布爾值。我也試過:這個。$。myinput.commit()來通知更新,並且這也不起作用 – sesteva 2014-10-30 19:35:54

+0

我沒有看到,你在測試什麼平臺? – sfeast 2014-10-30 20:30:48

+0

你的意思是「真」嗎?該字段爲空時無效。無論如何,這不起作用:該字段保持有效狀態。 – Fedy2 2014-10-31 07:24:06