EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: poeziafree on December 03, 2021, 11:59:10 PM



Title: How to bind Form Submit Function to the Content from Window Refresh (new URL)?
Post by: poeziafree on December 03, 2021, 11:59:10 PM
Hello,

I am stuck... Any help will be much appreciated.

After the user submits the form which is located in Window, there is refresh function from a new URL:

$('#windowPopUp').window('refresh', '/saoperatoro/editUser.php?id='+data.user);


the refresh URL loads new form. My question is how to add $('#...').form('submit', {... to the form that was loaded after refreshing the window?

Here is the full code:

Code:
function CreateOperator(){
       
        $.messager.progress({ title: 'მიმდინარეობს მონაცემების შენახვა', msg: 'გთხოვთ, დაელოდოთ...' });
$('#CreateOperator').form('submit', {
url: '/api-submitCreateOperator',
onSubmit: function(){
var isValid = $(this).form('validate');
if (!isValid){
$.messager.progress('close'); // hide progress bar while the form is invalid
}
return isValid; // return false will stop the form submission
},
success: function(data){
$.messager.progress('close'); // hide progress bar while submit successfully

        var data = eval('(' + data + ')');  // change the JSON string to javascript object
        if (data.success){
           
            //$('#windowPopUp').window('refresh', '/saoperatoro/editUser.php?id='+data.user);
           
            $('#windowPopUp').window({
                                title: 'მომხმარებლის რედაქტირება',
                                width: '80%',
                                height: 600,
                                modal: true,
                                resizable: true,
                                closeAnimation: 'hide',
                                minimize: 'animate',
                                collapsible: false,
                                href: '/saoperatoro/editUser.php?id='+data.user,
                                footer: '#windowPopUpFooter',
                                onBeforeLoad: function() {
                                    $(this).window('hideFooter');
                                    $.messager.alert('წარმატებით შესრულდა',data.message);
                                },
                                onLoad: function() {
                                    $(this).window('showFooter');
                                    $(this).window('footer').html('<a href="#" class="easyui-linkbutton" iconCls="icon-ok" style="width:80%;height:32px">Register</a> <a href="#" class="easyui-linkbutton" iconCls="icon-ok" style="width:20%;height:32px">Cancel</a>');
                                    $(this).window('footer').css('padding', '5px');
                                   


                                },
                                onMinimize: function() {



                                    var contents = $('#windowPopUp').contents();

                                    var id = 'create-operator';
                                    var title = '<uniqueID>' + id + '<\/uniqueID> მომხმარებლის შექმნა';


                                    var tabPanel = $('#wu-tabs');
                                    if (tabPanel.tabs('exists', title)) {
                                        tabPanel.tabs('select', title);
                                        return false;
                                    }


                                    tabPanel.tabs('add', {
                                        id: id,
                                        title: title,
                                        content: contents,
                                        fit: true,
                                        cls: 'pd3',
                                        closable: true
                                    });




                                }
                            });
           
           
           
           
            $('#operatorsIndex').datagrid('reload');
        }
        if (data.error){
            $.messager.alert('შეცდომა',data.message,'error');
        }
 
}
});
       
       
        }


Title: Re: How to bind Form Submit Function to the Content from Window Refresh (new URL)?
Post by: jarry on December 06, 2021, 02:03:49 AM
If you want to submit a form in the window, just to find the form and call the 'submit' method.
Code:
$('#windowPopUp').find('form').form('submit', {
//...
})


Title: Re: How to bind Form Submit Function to the Content from Window Refresh (new URL)?
Post by: poeziafree on December 07, 2021, 10:17:40 AM
Hi Jerry,

Thank you for your reply.

Is there any method to run the function after the refresh is done?

For example: $('#windowPopUp').window('refresh', '/saoperatoro/editUser.php?id='+data.user);

I need to detect when refresh is finished and then run the function...


Title: Re: How to bind Form Submit Function to the Content from Window Refresh (new URL)?
Post by: jarry on December 07, 2021, 11:05:16 PM
Please listen to the 'onLoad' event which will be triggered when calling the 'refresh' method to load the remote content.
Code:
$('#windowPopUp').window({
onLoad: function(){
//...
}
})