简体   繁体   English

失去对form.textfield的关注后,不显示值

[英]Value not displayed after losing focus on form.textfield

I have a custom grid and some cells have a cell editor , an Ext.form.TextField, in order to modify value of the cell. 我有一个自定义网格,有些单元格具有一个单元格编辑器Ext.form.TextField,以便修改单元格的值。 Here is how is defined the TextField: 这是如何定义TextField的:

var labelTextEditor = new Ext.form.TextField({
    allowBlank: false,
    maxLength: 256,
    id: "labelTextEditor",
    maxLengthText: Label.conf.ui.javascript.TooLongText,
    validateOnChange: true,
    validator: function(value) {
        console.log(value);
        if (value == "" && value.trim() == "") {
            return formatMessage(Label.conf.ui.supv.LabelMandatory);
        } else
            return true;
    },
    msgTarget: 'under',
    listeners: {
        focus( a, event, eOpts ){
            var rowIndex = customFieldGrid.getSelectionModel().getCurrentPosition().row;
            if(rowIndex !== undefined && rowIndex !== null){
                a.setValue(view.listOfServiceDefinition[0].customFields[rowIndex].labels[userLanguagePrefix]);
            }
        },
        blur(a, event, eOpts){
            var cellValue = a.getValue();
            if(cellValue !== undefined && cellValue !== null){
                a.setValue(cellValue);
            }else{
                a.setValue("");
            }
        }
    }
});

When I focus on the cell, it keeps me the value that was there before focusing on the cell, thanks to the focus listener. 当我专注于单元格时,由于有了焦点侦听器,它使我得以保留专注于该单元格之前的价值。 But when I lose focus, the cell displays nothing. 但是当我失去注意力时,单元格什么也没显示。 When I click back on it, the value is displayed again and can be edited. 当我单击它时,该值将再次显示并可以编辑。 So the problem is that when I lose focus, the value cannot be kept displayed on the cell. 所以问题是当我失去焦点时,该值将无法保持显示在单元格上。 I've tried to blur event but didn't help... 我试图模糊事件,但没有帮助...

Problem here is your blur event. 这里的问题是您的blur事件。 As Per Documentation blur event Fires when this Component loses focus. 根据文档 模糊事件,当此组件失去焦点时触发。 So in your case when you loosing focus your blur event is firing. 因此,当您失去焦点时,模糊事件就会触发。 And As I can see in your blur event You are setting some other values, Therefor it is coming as empty. 正如我在模糊事件中看到的那样,您正在设置其他一些值,因此它变成空的。

This line is causing an issue in your code : 此行导致您的代码出现问题:

else{
     a.setValue("");
    }

I also created one fiddler to understand blur and focus . 我还创建了一个提琴手来理解blurfocus

Fiddle 小提琴

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

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