簡體   English   中英

模糊/單擊Formpanel ExtJS 4無法正確訪問表單字段

[英]Blur/Click on Formpanel ExtJS 4 does not access form fields correctly

我有一個ExtJS Formpanel,並且在單擊表單時(不是在表單的任何字段上)都寫了一個偵聽器,它工作正常。

  1. 即使在將Ext.FocusManager.Enable()設置為true之后,我也無法使“模糊”工作。 我想念什么?

  2. 我無法從事件處理程序中訪問FormPanel Click事件的表單字段。 當我這樣做時-this.up。('form')。get。(fielname).value [在表單字段上的事件處理程序中正常工作。]它說元素未定義。 如何在這里訪問表單元素?

添加代碼段-

// Call it Object A     
Ext.create.('Ext.form.Panel', {

       id : xyz,


       items: [
       {
          xtype : 'textfield',
          name : 'test',
          fieldLabel : 'Name'
    }

    listeners : { // listener on the formPanel; not on any of its element
      click : {
            console.log("this works" );
     },
     focus : {
            console.log('this does not work');
    }

    }
    ]


    }

我這樣做是為了可以訪問另一個對象的值,例如B.field。

Onload我能夠獲取B.field的值。 但是,當用戶更改位於不同選項卡上的B.field的值時,我無法在A中獲取B.field的更改后的值。我只是在尋找避免對數據庫進行Ajax調用的方法。

在此先感謝您的時間。

沒有代碼中的任何示例可供參考,很難確定您要執行的操作。

可能只是您需要修復查詢表單元素的方式。 例如,工具欄中的元素不是表單的子元素,因此向上/向下不起作用。

我認為您無法收聽事件focusblurclick表單。 即使可以,我不確定您是否願意這樣做。 取而代之的是,更常見的是focus於某個字段或click一個按鈕。

示例1表單,其中字段使用focus ,按鈕使用click

http://codepen.io/anon/pen/qEPRge?editors=001

;(function(Ext) {
  Ext.onReady(function() {
    console.log("Ext.onReady")

    var form = new Ext.create("Ext.form.Panel", {
      title: "person"
      ,items: [
        {itemId: "fld-id", fieldLabel: "id", name: "id", value: "1", xtype: "textfield", labelAlign: "top", labelSeparator: ""}
        ,{itemId: "fld-name", fieldLabel: "name", name: "name", value: "Emily", xtype: "textfield", labelAlign: "top", labelSeparator: ""}
        ,{itemId: "btn-submit", text: "submit", xtype: "button"}
      ]
    })
    form.on("afterrender", function(component) {
      console.log("form.afterrender")
    })
    form.render(Ext.getBody())

    form.queryById("fld-id").on("focus", function(component) {
      console.log("fld-id.focus")
    })

    form.queryById("fld-name").on("focus", function(component) {
      console.log("fld-name.focus")
    })

    form.queryById("btn-submit").on("click", function(component) {
      console.log("btn-submit.click")
      console.log("fld-id.value:")
      console.log(component.up("form").queryById("fld-id").getValue())
      console.log("fld-name.value:")
      console.log(component.up("form").queryById("fld-name").getValue())
    })
  })
})(Ext)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM