2013-12-12 55 views
0

這是我在我的FormPanel中文本框:一個formPanels文本框的值應該是一個HREF鏈接

{ 
    xtype: 'textfield', 
    fieldLabel: 'Homepage', 
    name: 'homepage', 
    tabIndex: 4, 
    padding: '10' 
} 

我想這顯示是一個可點擊的鏈接加載的值。

編輯

因爲網頁時,「HTTP://」開頭不會在新選項卡中顯示,我改變了解決方案有點像這樣:

listeners: { 
    render: function (field) { 
     this.getEl().on('click', function (e, t, eOpts) { 
      var url = e.target.value; 
      if (url != '') { 
      if (url.indexOf("http://") != -1) { 
       var win = window.open(url, '_blank'); 
      } else { 
       var win = window.open('http://' + url, '_blank'); 
      } 
      win.focus(); 
      } 
     } 
     } 
} 

回答

2

有沒有辦法可以實現你的願望。對於'鏈接'你必須 使用另一個組件可能是一個帶有鏈接的標籤。 但隨着一些技巧你可以在一個文本框的值顯示爲鏈接。對於,你可以做這樣的事情:

{ 
    xtype: 'textfield', 
    name: 'name', 
    id:'link', 
    fieldStyle: 'color: blue; text-decoration:underline; cursor:pointer', 
    listeners: { 
     render: function (field) { 
      this.getEl().on('click', function (e, t, eOpts) { 
       console.log(e); 
       //here you need to do some hack around to restrict changing href,only on click of input in the textfield.Could not achieve that,but tried to give some idea. 
       var url = e.target.value; 
       if(url != ''){ 
        window.location=""; 
       } 
      }); 
     } 
    } 
} 

希望這有助於你:-)

+0

yes確實有幫助,但我不得不檢查它是否以「http://」開頭,因爲它沒有顯示網頁。謝謝! – Paparis

0

要做到這一點,你可以使用渲染功能如下:

{ 
    xtype : 'displayfield', 
    id: 'yourId', 
    name:'yourName', 
    fieldLabel: 'This is the label', 
    renderer: function(data, field) { 
     return '<a href="'+data+'">'+data+'</a>' 
    } 
} 

它可能不是最完美的解決方案,但它的工作原理:)

相關問題