2012-07-19 63 views
2

我有一個即時通訊應用程序,它的目標是在移動設備上運行。我希望使用新的HTML5 input type="tel"來接受電話輸入,並讓移動設備提示輸入正確的鍵盤輸入(數字)。GWT HTML 5輸入類型電話

我想使用一個GWT文本框,但不能看到一種方法讓它呈現正確的輸入類型的HTML。

對此有何意見?

在此先感謝。

回答

0

以mgwt(http://www.m-gwt.com)表示的移動設備GWT有很多不同的輸入(也是電話輸入)。你可能想看看它。

+0

今天看了一下這個庫。好的一套小部件感謝您的建議 – user1128157 2012-07-20 04:08:07

5

簡單的方式

TextBox tel=new TextBox(); 
tel.getElement().setAttribute("type", "tel"); 

TextBox email=new TextBox(); 
email.getElement().setAttribute("type", "email"); 

TextBox url=new TextBox(); 
url.getElement().setAttribute("type", "url"); 
+0

如果在IE <= v9上運行,這將會跳閘。考慮爲這些版本的IE手動編碼a,並使用GWT的延期綁定來管理額外的代碼。 – Carl 2012-11-05 12:11:53

2

創建自定義窗口小部件:

package com.example; 

import com.google.gwt.dom.client.InputElement; 
import com.google.gwt.user.client.ui.TextBoxBase; 

public class TelephoneBox extends TextBoxBase { 

    public TelephoneBox() { 
     super(createTelInput()); 
    } 

    private static native InputElement createTelInput() /*-{ 
     var input = document.createElement("input"); 
     input.setAttribute("type", "tel"); 
     return input; 
    }-*/; 
} 

然後你就可以在UiBinder的使用它:

<ui:UiBinder ... xmlns:my="urn:import:com.example"> 
... 
<my:TelephoneBox/>