YUI Dialog,表单提交成功后回调

时间:2013-03-07 10:46:28

标签: javascript yui

我有一个对话框弹出窗口,它使用YUI库发布表单,到目前为止这是有效的。但是如何在成功提交表单后调用其他函数。我基本上需要从表单提交创建的数据库表行中提取一个字段。

到目前为止,这是我的代码:

 var callback = {

    success: function(result) {

        form = result.responseText;

        dialog = new YAHOO.widget.Dialog('dialog1', {
            width: '400px',

            fixedcenter : "contained",
            visible : false,
            draggable: true,
            effect:[{effect:YAHOO.widget.ContainerEffect.SLIDE, duration:0.2},
                    {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.2}],
            modal:true
        });

        dialog.setHeader(titleval);
        dialog.setBody(form);

        var handleCancel = function() {
            this.cancel();

        };
        var handleSubmit = function() {

            date_box = dialog.getData().date;
            reason_box = dialog.getData().reason;
            hours = dialog.getData().date_start_hours;
            mins = dialog.getData().date_start_minutes;
            format = dialog.getData().format;
            ampm = dialog.getData().date_start_meridiem;
            username = dialog.getData().user;

            //basic validation
            if(date_box == '' && reason_box == '' ){

                document.getElementById('error1').style.display = "";
                document.getElementById('error2').style.display = "";

            }else if(date_box == '' || !isDate(date_box)){

                document.getElementById('error1').style.display = "";
                document.getElementById('error2').style.display = "none";

            }
            else if(reason_box == '' && !isDate(date_box)){

                document.getElementById('error1').style.display = "";
                document.getElementById('error2').style.display = "";

            }
            else if(reason_box == ''){

                document.getElementById('error1').style.display = "none";
                document.getElementById('error2').style.display = "";

            }
            else{

                 this.submit();
                 update(date_box, hours, mins, format, ampm, reason_box, username);
            }

        };
        var myButtons = [{ text: "Save", handler: handleSubmit, isDefault: true },
                         { text: "Cancel", handler:handleCancel }];

        dialog.cfg.queueProperty("buttons", myButtons);
        dialog.render(document.body);
        dialog.show();

        document.getElementById('call_id').value = id.value;
        eval(document.getElementById('script').innerHTML);
        eval(document.getElementById('script2').innerHTML);

    }

}

var connectionObject = YAHOO.util.Connect.asyncRequest ("GET", "index.php?entryPoint=Reschedule&call_id="+id.value, callback);

1 个答案:

答案 0 :(得分:0)

我相信此页面包含答案:http://developer.yahoo.com/yui/container/dialog/

向下滚动到标题为“提交表​​单数据”的部分。它显示了如何配置回调。