MooTools 表单请求在提交后恢复值

发布于 2024-11-18 12:34:26 字数 422 浏览 1 评论 0原文

我有一个 MooTools 表单请求给我带来了问题。

提交表单后,这些值将更改回生成表单时的值。

var formRequest = new Form.Request(myFormValidator, dialogBox, {

    onSend: function(){
        dialogBox.setStyle('display','block');
        dialogBox.fade(1);
        dialogBox.set('html','Saving');

    },
    onSuccess: function(response) {

        dialogBox.setStyle('display','block');
        dialogBox.fade(1);
    }
});

I have a MooTools form request that is causing problems for me.

When the form is submitted, the values change back to the values they were when the form was generated.

var formRequest = new Form.Request(myFormValidator, dialogBox, {

    onSend: function(){
        dialogBox.setStyle('display','block');
        dialogBox.fade(1);
        dialogBox.set('html','Saving');

    },
    onSuccess: function(response) {

        dialogBox.setStyle('display','block');
        dialogBox.fade(1);
    }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻安 2024-11-25 12:34:26

解决方案

在更彻底地搜索文档之后,我发现表单默认会自行重置。去算算吧。有一个文字值 resetForm 需要设置为 false

var formRequest = new Form.Request(myFormValidator, dialogBox, {

    resetForm: false,
    onSend: function(){
        dialogBox.setStyle('display','block');
        dialogBox.fade(1);
        dialogBox.set('html','Saving');

    },
    onSuccess: function(response) {

        dialogBox.setStyle('display','block');
            dialogBox.fade(1);

    }
});

解释

默认值似乎违反直觉,至少在编辑表单的上下文中是这样。当您对记录进行更改并保存时,您会希望所做的更改保留在屏幕上,而不是更改回来。

表单字段行为示例(resetForm:true)

                Change                     Submit
Name: [ Bob ]     -->     Name: [ Bobby ]     -->     Name: [ Bob ]

表单字段行为示例(resetForm:false)

                Change                     Submit
Name: [ Bob ]     -->     Name: [ Bobby ]     -->     Name: [ Bobby ]

开发者的初衷

那么为什么会默认清除表单呢?我能理解它的唯一方法是在快速输入表格的上下文中。填写完表格后,它会清除,以便您可以快速输入另一条记录。

表单字段行为示例 (resetForm:true)

                Change                     Submit
Name: [     ]     -->     Name: [ Bobby ]    -->     Name: [     ]
Name: [     ]     -->     Name: [ David ]    -->     Name: [     ]
Name: [     ]     -->     Name: [ Susan ]    -->     Name: [     ]

The Solution

After searching through the documentation a little more thoroughly, I found the form resets itself by default. Go figure. There is a literal value resetForm that needs to be set to false.

var formRequest = new Form.Request(myFormValidator, dialogBox, {

    resetForm: false,
    onSend: function(){
        dialogBox.setStyle('display','block');
        dialogBox.fade(1);
        dialogBox.set('html','Saving');

    },
    onSuccess: function(response) {

        dialogBox.setStyle('display','block');
            dialogBox.fade(1);

    }
});

The Explanation

The default seems counter-intuitive, at least in the context of an edit form. When you make changes to a record and save it, you would expect your changes to stay on screen, not change back.

Example Form Field Behavior (resetForm:true)

                Change                     Submit
Name: [ Bob ]     -->     Name: [ Bobby ]     -->     Name: [ Bob ]

Example Form Field Behavior (resetForm:false)

                Change                     Submit
Name: [ Bob ]     -->     Name: [ Bobby ]     -->     Name: [ Bobby ]

The Original Intention of the Developers

So why is the default to clear the form? The only way I can make sense of it is in the context of a quick-entry form. After you fill out the form it would clear so you can enter another record quickly.

Example Form Field Behavior (resetForm:true)

                Change                     Submit
Name: [     ]     -->     Name: [ Bobby ]    -->     Name: [     ]
Name: [     ]     -->     Name: [ David ]    -->     Name: [     ]
Name: [     ]     -->     Name: [ Susan ]    -->     Name: [     ]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文