Javascript-форум (https://javascript.ru/forum/)
-   ExtJS (https://javascript.ru/forum/extjs/)
-   -   Простенький вопрос - focus для компонента модального окна? (https://javascript.ru/forum/extjs/24232-prostenkijj-vopros-focus-dlya-komponenta-modalnogo-okna.html)

JDev 22.12.2011 13:09

Простенький вопрос - focus для компонента модального окна?
 
Здравств, значит тем похожых много, но я только начал разбиратся, не знаю как правильно прописать.

Так вот, при загрузке окна мне нужно выставить фокус в каком0то компоненте, пускай это будет первое текстовое поле.

нашел код
Ext.get('t1').focus();

не знаю где его вставить, и корректен ли он.
нашел код
listeners : {
											afterrender : function(field) {
												field.focus(true);
					}
				}

но я успеваю только заметить курсор - потом он исчезает.

Вот вся функция, - подскажите пожалуйста - как установить фокус?
var me = this;

				Ext.apply(this, {
							height : 500,
							width : 500,
							modal : true,
							title : 'modal Window 500x500',
							plain : true,
							border : false,
							resizable : false,
							draggable : false,
							closable : true,

							items : [{
										xtype : 'textfield',
										itemId : 'desc',
										margin : 5,
										width : 400,
										focusCls : 'x-form-focus',
										fieldLabel : 'Beschreibung'
									}, {
										xtype : 'textfield',
										itemId : 't1',
										margin : 5,
										width : 400,
										fieldLabel : 'Textfield1'
									}, {
										xtype : 'textfield',
										itemId : 't2',
										margin : 5,
										width : 400,
										fieldLabel : 'Textfield2'
										/*listeners : {
											afterrender : function(field) {
												field.focus(true);
											}
										}*/

									}, {
										xtype : 'textfield',
										itemId : 't3',
										margin : 5,
										width : 400,
										fieldLabel : 'Textfield3'
									}, {
										xtype : 'textfield',
										itemId : 't4',
										margin : 5,
										width : 400,
										fieldLabel : 'Textfield4'
									}, {
										xtype : 'tabpanel',
										plain : true,
										layoutOnTabChange : true,
										margin : 5,
										width : 450,
										height : 200,
										items : [{
													xtype : 'panel',
													title : 'Tab1',
													html : 'A simple Tag'
												}, {
													xtype : 'panel',
													title : 'Tab2',
													html : 'Another one'
												}]
									}],

							buttonAlign : 'center',
							buttons : [{
										text : 'OK',
										handler : function() {
											me.close();
										}
									}]
						});


Спасибо!

nekto_O 22.12.2011 13:35

у окна
listeners: {
   show: function(){
      this.getComponent('t1').focus(true);
   }
}

JDev 22.12.2011 14:05

Спасибо, вставил в этот блок
{
										xtype : 'textfield',
										itemId : 't2',
										margin : 5,
										width : 400,
										fieldLabel : 't2',
										listeners : {
											show : function() {
												this.getComponent('t2').focus(true);
											}
										}
									}


не работает

nekto_O 22.12.2011 15:46

Цитата:

Сообщение от JDev
не работает

внимательно читайте
Цитата:

Сообщение от nekto_O
у окна


JDev 22.12.2011 15:58

Действительно не заметил, -
Вот, мне кажется правильно на этот раз?
На такая же фишка, курсор появляется на мгновение и исчезает. :(

Ext.define('My.view.core.dialog.par.ParExampleModalWindow', {
			extend : 'Ext.Window',
			alias : 'widget.core_dialog_par_example_modal_window',

			// constructor function
			constructor : function(config) {

				var me = this;

				Ext.apply(this, {
							height : 500,
							width : 500,
							modal : true,
							title : 'Modal Window 500x500',
							plain : true,
							border : false,
							resizable : false,
							draggable : false,
							closable : true,

							items : [{
										xtype : 'textfield',
										itemId : 'desc',
										margin : 5,
										width : 400,
										focusCls : 'x-form-focus',
										fieldLabel : 'Beschreibung'
									}, {
										xtype : 'textfield',
										itemId : 't1',
										margin : 5,
										width : 400,
										fieldLabel : 'Textfield1'
									}, {
										xtype : 'textfield',
										itemId : 't2',
										margin : 5,
										width : 400,
										fieldLabel : 't2'

									}, {
										xtype : 'textfield',
										itemId : 't3',
										margin : 5,
										width : 400,
										fieldLabel : 'Textfield3'
									}, {
										xtype : 'textfield',
										itemId : 't4',
										margin : 5,
										width : 400,
										fieldLabel : 'Textfield4'
									}, {
										xtype : 'tabpanel',
										plain : true,
										layoutOnTabChange : true,
										margin : 5,
										width : 450,
										height : 200,
										items : [{
													xtype : 'panel',
													title : 'Tab1',
													html : 'A simple Tag'
												}, {
													xtype : 'panel',
													title : 'Tab2',
													html : 'Another one'
												}]
									}],

							listeners : {
								show : function() {
									this.getComponent('t2').focus(true);
								}
							},

							buttonAlign : 'center',
							buttons : [{
										text : 'OK',
										handler : function() {
											me.close();
										}
									}]
						});

				My.view.core.dialog.par.ParExampleModalWindow.superclass.constructor
						.apply(this, arguments);

			}

		});

JDev 05.01.2012 12:59

Никто не сталкивался? :(

VitalikSanich 06.01.2012 05:33

Не факт, но попробуйте поиграться параметром delay, поставьте чуть больше, например 100,
this.getComponent('t2').focus(true, 100);
проверьте, если будет все нормально, то можно поуменьшать

JDev 06.01.2012 15:25

Спасибо, попробую. :)


Часовой пояс GMT +3, время: 00:11.