1. #1
    Sencha User chalu's Avatar
    Join Date
    Feb 2008
    Location
    Benin City, Nigeria
    Posts
    480
    Vote Rating
    1
    chalu is on a distinguished road

      0  

    Thumbs up [Solved] Programmatically click an Ext.Button ??

    [Solved] Programmatically click an Ext.Button ??


    How can I simulate a click on an Ext.Button, that is, code the click on the button when some event occurs instead of a user actually clicking it. How can this be possible if our target button is hidden ??

  2. #2
    Sencha User chalu's Avatar
    Join Date
    Feb 2008
    Location
    Benin City, Nigeria
    Posts
    480
    Vote Rating
    1
    chalu is on a distinguished road

      0  

    Question


    Any suggestions on this yet ?? I have a Ext.Button but for some reason it's got to be hidden, so the user won't see it to click on it, I've got to script the click on it when the user interacts with something they can see. It's urgent please.Thanks

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,507
    Vote Rating
    56
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    myButton.handler.call(myButton.scope, myButton, Ext.EventObject())

  4. #4
    Sencha User chalu's Avatar
    Join Date
    Feb 2008
    Location
    Benin City, Nigeria
    Posts
    480
    Vote Rating
    1
    chalu is on a distinguished road

      0  

    Question


    firebug says Ext.EventObject() is not a function
    I am actually using the browse button extension, it's constructor is thus
    Code:
    initComponent: function(){
    	Ext.ux.form.BrowseButton.superclass.initComponent.call(this);
    	// Store references to the original handler and scope before nulling them.
    	// This is done so that this class can control when the handler is called.
    	// There are some cases where the hidden file input browse button doesn't completely cover the Ext.Button.
    	// The handler shouldn't be called in these cases. 
            // It should only be called if a new file is selected on the file system.  
    	this.originalHandler = this.handler;
    	this.originalScope = this.scope;
    	this.handler = null;
    	this.scope = null;
    }
    So I am applying your suggestion thus:
    Code:
    this.browseBtn.originalHandler.call(this.browseBtn.originalScope, this.browseBtn, Ext.EventObject());

  5. #5
    Sencha User chalu's Avatar
    Join Date
    Feb 2008
    Location
    Benin City, Nigeria
    Posts
    480
    Vote Rating
    1
    chalu is on a distinguished road

      0  

    Question


    This is the handler where I want to do the 'click', and this is what I have now:
    Code:
       onBoxClick: function(evt, el){
        	//myButton.handler.call(myButton.scope, myButton, Ext.EventObject())
        	this.browseBtn.originalHandler.call(this.browseBtn.originalScope, this.browseBtn, evt);
        }
    The onBoxClick function is attached to the click event of an Ext.Element object, I want to click the browse button when the Ext.Element object is clicked. The code in the previous post gives an error, this one just does nothing, what am I missing please

  6. #6
    Ext User
    Join Date
    Mar 2008
    Location
    Houston, TX
    Posts
    148
    Vote Rating
    0
    rvent is on a distinguished road

      0  

    Default


    Maybe you can just disable the button and then on the click event you just have to enable it...?

  7. #7
    Sencha Premium Member neenhouse's Avatar
    Join Date
    Dec 2007
    Location
    Austin
    Posts
    168
    Vote Rating
    1
    neenhouse is on a distinguished road

      0  

    Default


    I have successfully simulated click's in the past using the plain old school dom function "click()". Try grabbing your components Dom, then browse it for that function.
    I love ext.

  8. #8
    Sencha User chalu's Avatar
    Join Date
    Feb 2008
    Location
    Benin City, Nigeria
    Posts
    480
    Vote Rating
    1
    chalu is on a distinguished road

      0  

    Thumbs up


    Post #5 is actually correct, my error is from some where else . This proves how to pro grammatically click a Ext.Button

  9. #9
    Ext User
    Join Date
    May 2008
    Posts
    5
    Vote Rating
    0
    kazukin6 is on a distinguished road

      0  

    Default the little correction

    the little correction


    Animal's solution did a trick for me

    but

    Code:
    myButton.handler.call(myButton.scope, myButton, Ext.EventObject)
    not

    Code:
    myButton.handler.call(myButton.scope, myButton, Ext.EventObject())

  10. #10
    Sencha User
    Join Date
    Jan 2009
    Posts
    18
    Vote Rating
    10
    MakFracta will become famous soon enough

      0  

    Default This worked for me

    This worked for me


    I found 2 ways:

    1)Create the event code in a function and call the function from both sides: btn.on("clic", ...) and from the code you want to simulate the click.

    2)Use: btnView.btnEl.dom.click();

    See you