1. #1
    Sencha User Dumas's Avatar
    Join Date
    Dec 2008
    Location
    Vienna, Austria
    Posts
    564
    Answers
    4
    Vote Rating
    8
    Dumas is on a distinguished road

      0  

    Default Unanswered: Closing an Ext.Msg.prompt thought code

    Unanswered: Closing an Ext.Msg.prompt thought code


    How can I virtually "press" the ok button of an Ext.Msg.prompt and trigger the callback function with the buttonId value 'ok'?

    thanks
    Roland

  2. #2
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,135
    Answers
    129
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    Just wondering why you would need the prompt in this case? Are you talking about in the event that the user keys in values into the textfield and then presses the 'Done' button on the virtual keyboard then you want the prompt to disappear?

  3. #3
    Sencha User Dumas's Avatar
    Join Date
    Dec 2008
    Location
    Vienna, Austria
    Posts
    564
    Answers
    4
    Vote Rating
    8
    Dumas is on a distinguished road

      0  

    Default


    Yes, exactly.

    Since this is not provided out of the box I wanted to add this. It works by keeping a reference to the Ext.Msg.prompt() result and and calling result.hide();, but a static method would be nicer

  4. #4
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,135
    Answers
    129
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    You'll notice that in the source code for Ext.MessageBox, there is a 'prompt' config that you can specify.

    Code:
    /**
     * @cfg {String} message
     * The message to be displayed in the {@link Ext.MessageBox}.
     * @accessor
     */
    message: null,
    
    
    /**
     * @cfg {String} msg
     * The message to be displayed in the {@link Ext.MessageBox}.
     * @removed 2.0.0 Please use {@link #message} instead.
     */
    
    
    /**
     * @cfg {Object} prompt
     * The configuration to be passed if you want an {@link Ext.field.Text} or {@link Ext.field.TextArea} field
     * in your {@link Ext.MessageBox}.
     *
     * Pass an object with the property "multiline" with a value of true, if you want the prompt to use a TextArea.
     *
     * Alternatively, you can just pass in an object which has an xtype/xclass of another component.
     *
     *     prompt: {
     *         xtype: 'textarea',
     *         value: 'test'
     *     }
     *
     * @accessor
     */
    prompt: null,
    You can add a listener to your textfield prompt for the 'keyup' event and when the key value is 13 or 10 or 11 (can't remember which is which), you can go to the function.
    Code:
    //something like
    
    Ext.Msg.show({
        title: 'Prompt',
        message: 'This is prompt',
        prompt: {
            xtype: 'textfield',
            listeners: {
                keyup: (fld, e){
                    if (e.browserEvent.keyCode == 13 || e.browserEvent.keyCode == 10 || e.browserEvent.keyCode == 11) {
                        e.stopEvent();
                        fld.element.dom.blur();
                        window.scrollTo(0,0);
                        //do function and hide prompt
                    }
                }
            }
        }
    });

  5. #5
    Sencha User Dumas's Avatar
    Join Date
    Dec 2008
    Location
    Vienna, Austria
    Posts
    564
    Answers
    4
    Vote Rating
    8
    Dumas is on a distinguished road

      0  

    Default


    Hello,

    sorry for the late respond. This blurs the field, but it doesn't close it.
    I still need to close the prompt and trigger the prompt callback...

    It works when I do this instead of the blur:
    Ext.Msg.onClick(Ext.Msg.buttonsToolbar.getItems().getByKey('ok'));

    But this is really ugly code, since I'm using private functions here.

    Any better idea?

    Thanks
    Roland

  6. #6
    Sencha User
    Join Date
    Sep 2012
    Posts
    65
    Answers
    7
    Vote Rating
    1
    warrean is on a distinguished road

      0  

    Default


    Hi,


    I don't know if it's an option, but you can manually provide the button-configuration:
    Code:
    Ext.Msg.show(                {
                        title : 'Confirm',
                        message : "Are you sure you? ",
                        buttons : [
                            {
                                itemId: 'ok'
                                text   : 'Yes'
                            }
                         ],
                         fn: function (buttonId, value, opt) {
                          .....
    And then later on access its 'itemId' property and fire the click event
    Code:
    Ext.ComponentQuery.query('#ok').click()

  7. #7
    Sencha User Dumas's Avatar
    Join Date
    Dec 2008
    Location
    Vienna, Austria
    Posts
    564
    Answers
    4
    Vote Rating
    8
    Dumas is on a distinguished road

      0  

    Default


    I'm looking for a generic version, so I will go with the following:

    PHP Code:
    /**
     * Prompts should by default close on an enter press
     */
    Ext.Msg.on('show', function(cmp) {
        if(
    Ext.Msg.getPrompt() === null){
            return; 
    // there is a config object this time
        
    }
        
    // every time there is a prompt config, apply listener
        
    Ext.Msg.getPrompt().on('keyup', function(fielde) {
            if(
    e.browserEvent.keyCode===13) {
                
    e.stopEvent();
                
    // fake a on-button press
                
    Ext.Msg.onClick(Ext.Msg.buttonsToolbar.getItems().getByKey('ok'));
            }
        });
    }); 
    thanks for the help!
    Roland

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar