Ext


Go Back   Ext JS Forums > Ext JS Premium Forums > Ext: Feature Requests

Reply
 
Thread Tools
  #1  
Old 08-21-2007, 07:24 AM
mdissel mdissel is offline
Ext JS Premium Member
 
Join Date: Mar 2007
Location: NL
Posts: 547
mdissel is on a distinguished road
Default tooltip on Ext.form.Field / Labels

I want to define some a tooltip on a Ext.form.Field component. Optionally you want to show the tooltip on the complete control or only on the control or on the label..

Thanks

Marco
Reply With Quote
  #2  
Old 08-27-2007, 04:38 PM
mdissel mdissel is offline
Ext JS Premium Member
 
Join Date: Mar 2007
Location: NL
Posts: 547
mdissel is on a distinguished road
Default

(using 2.0 codebase)
This is what i've got sofar... But i want to show the tooltip on the complete div that is surrounding the fields (label and input box). Any tips how to find that div?

Ext.override(Ext.form.Field, {
  afterRender : function() {
		Ext.form.Field.superclass.afterRender.call(this);		
		if (this.description) {
				Ext.QuickTips.register({
				target:  this.container || this.el,
//				title: this.fieldLabel || '',
				text: this.description
			});
  	}
  }
});
The rendered HTML is like this. I want to show the description when the mouse hovers in the outermost div.. (if possible, else on label and inputbox)

<div tabindex="-1" class="x-form-item">
  <label class="x-form-item-label" style="width: 125px;" for="ext-comp-1004">Client Code:</label>
   <div style="padding-left: 130px;" id="x-form-el-ext-comp-1004" class="x-form-element">
     <input type="text" name="SearchClientCode" id="ext-comp-1004" autocomplete="off" size="20" class="x-form-text x-form-field" tabindex="1" style="width: 231px;"/>
  </div>
</div>
Thanks

Marco
Reply With Quote
  #3  
Old 09-09-2007, 08:40 PM
danh2000 danh2000 is offline
Ext JS Premium Member
 
Join Date: May 2007
Posts: 689
danh2000 is on a distinguished road
Default

Here's an example I use for check box (it's parent div has a class of 'x-form-check-wrap'):


Ext.QuickTips.init();
Ext.override(Ext.form.CheckBox, {
  
afterRender : function() {
        
Ext.form.CheckBox.superclass.afterRender.call(this);            
        var 
qt this.qtipText;
        if(
qt){
                
Ext.QuickTips.register({
                
target:  this,
                
title'',
                
textqt,
                
enabledtrue
            
});
            var 
wrapDiv this.getEl().up('div.x-form-check-wrap');
                
            if(
wrapDiv){
                var 
label wrapDiv.child('label');
                
Ext.QuickTips.register({
                    
target:  label,
                    
title'',
                    
textqt,
                    
enabledtrue
                
});
            }
          }
  }
}); 
I then simply provide a qtipText property to any form field - the field and it's label both get a qtip... you could easily extend this by registering another qtip with the target set to the containing div (in my example wrapDiv).
Reply With Quote
  #4  
Old 09-09-2007, 10:22 PM
danh2000 danh2000 is offline
Ext JS Premium Member
 
Join Date: May 2007
Posts: 689
danh2000 is on a distinguished road
Default

Here's a more dynamic approach that seems to work for all fields:


Ext.override(Ext.form.Field, {
  
afterRender : function() {            
        if(
this.qtipText){
                
Ext.QuickTips.register({
                
target:  this.getEl(),
                
title'',
                
textthis.qtipText,
                
enabledtrue
            
});
            var 
label findLabel(this);
            if(
label){
                
Ext.QuickTips.register({
                    
target:  label,
                    
title'',
                    
textthis.qtipText,
                    
enabledtrue
                
});
            }
          }
          
Ext.form.Field.superclass.afterRender.call(this);
  }
});

var 
findLabel = function(field) {
    
    var 
wrapDiv null;
    var 
label null
    
//find form-element and label?
    
wrapDiv field.getEl().up('div.x-form-element');
    if(
wrapDiv
    {
        
label wrapDiv.child('label');        
    }
    if(
label) {
        return 
label;
    }
    
    
//find form-item and label
    
wrapDiv field.getEl().up('div.x-form-item');
    if(
wrapDiv
    {
        
label wrapDiv.child('label');        
    }
    if(
label) {
        return 
label;
    }    


Last edited by danh2000; 09-09-2007 at 10:46 PM.. Reason: removed console.log
Reply With Quote
  #5  
Old 11-28-2007, 05:09 AM
sigaref sigaref is offline
Ext User
 
Join Date: Nov 2007
Location: Munich
Posts: 30
sigaref is on a distinguished road
Default

Thank you very much for this code. I have changed it for viewing a small Image with Tooltip next to the label, the code is:

 Ext.override(Ext.form.Field, {
  afterRender : function() {  
  	       
        if(this.helpText){

            var label = findLabel(this);

            if(label)
            {                 	  
            	    	
             	var helpImage = label.createChild({
             			tag: 'img', 
             			src: '/images/global/questionmark.gif',
             			style: 'margin-bottom: 0px; margin-left: 5px; padding: 0px;',
             			width: 10,
             			height: 11
             		});            	
             	
	                   	
                Ext.QuickTips.register({
                    target:  helpImage,                   
                    text: this.helpText,
                    enabled: true
                });
                
            }
          }
        Ext.form.Field.superclass.afterRender.call(this);    
        this.initEvents();  
  }
});

var findLabel = function(field) {
    
    var wrapDiv = null;
    var label = null

    //find form-item and label
    wrapDiv = field.getEl().up('div.x-form-item');
    if(wrapDiv) 
    {
        label = wrapDiv.child('label');        
    }
    if(label) {
        return label;
    } 

    /*
    
    //find form-element and label?
    wrapDiv = field.getEl().up('div.x-form-element');
    if(wrapDiv) 
    {
        label = wrapDiv.child('label');        
    }
    if(label) {
        return label;
    }
    */
   
}
Edit: Added "this.initEvents(); "

Last edited by sigaref; 11-28-2007 at 05:43 AM.. Reason: Bug fixed in Code
Reply With Quote
  #6  
Old 08-18-2008, 09:09 PM
Zyclops's Avatar
Zyclops Zyclops is offline
Ext User
 
Join Date: Jul 2007
Location: Adelaide, South Australia
Posts: 138
Zyclops is on a distinguished road
Send a message via MSN to Zyclops
Default

Thanks Guys!

I modified so I could also add just on labels as well as specify a qtip title.

Ext.override(Ext.form.Label, {
  afterRender : function() {            
    if(this.qtipText){
      Ext.QuickTips.register({
        target:  this.getEl(),
        title: this.qtipTitle,
        text: this.qtipText,
        enabled: true
      });
    }
    Ext.form.Label.superclass.afterRender.call(this);
  }   
});


Ext.override(Ext.form.Field, {
  afterRender : function() {   
    var findLabel = function(field) {
      var wrapDiv = null;
      var label = null;
      //find form-element and label?
      wrapDiv = field.getEl().up('div.x-form-element');
      if(wrapDiv) {
        label = wrapDiv.child('label');        
      }
      if(label) {
        return label;
      }

      //find form-item and label
      wrapDiv = field.getEl().up('div.x-form-item');
      if(wrapDiv) {
        label = wrapDiv.child('label');        
      }
      if(label) {
        return label;
      }    
    };   
    
    if(this.qtipText){
      Ext.QuickTips.register({
        target:  this.getEl(),
        title: this.qtipTitle,
        text: this.qtipText,
        enabled: true
      });
      var label = findLabel(this);
        if(label) {
          Ext.QuickTips.register({
            target:  label,
            title: this.qtipTitle,
            text: this.qtipText,
            enabled: true
          });
        }
    }
    Ext.form.Field.superclass.afterRender.call(this);
  }
});
Reply With Quote
  #7  
Old 08-19-2008, 01:04 AM
Zyclops's Avatar
Zyclops Zyclops is offline
Ext User
 
Join Date: Jul 2007
Location: Adelaide, South Australia
Posts: 138
Zyclops is on a distinguished road
Send a message via MSN to Zyclops
Default

I found the override prevents some comboboxes and other third party extensions from working. Overriding afterRender at all seems to cause the issue.
Reply With Quote
  #8  
Old 10-29-2008, 12:19 PM
djbokka's Avatar
djbokka djbokka is offline
Ext User
 
Join Date: Oct 2008
Location: Denver, Colorado, USA
Posts: 11
djbokka is on a distinguished road
Default

Zyclops,

I ran into the same issue with comboboxes. Default values, width, etc. are removed. Have you, by chance, found a workaround for this?
Reply With Quote
  #9  
Old 10-29-2008, 12:54 PM
jack.slocum's Avatar
jack.slocum jack.slocum is offline
Ext JS - Development Team
 
Join Date: Mar 2007
Posts: 6,941
jack.slocum is on a distinguished road
Default

The original posted override removes the default form field afterRender functionality.

In particular, these two calls:

this.initEvents();
this.initValue();

You can add them back in the override and it should work fine.
__________________
Jack Slocum
Ext JS - Core Development Team
jack@extjs.com
Reply With Quote
  #10  
Old 10-29-2008, 12:59 PM
djbokka's Avatar
djbokka djbokka is offline
Ext User
 
Join Date: Oct 2008
Location: Denver, Colorado, USA
Posts: 11
djbokka is on a distinguished road
Default

thanks jack,

it did work for the value but it still doesn't read the width. should this be covered by this.initEvents()?
Reply With Quote
Reply

Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT -5. The time now is 06:47 PM.

© 2006-2009 Ext, LLC
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.