开发者

How to require a user to update a form in Rails

I have a complex page in my Rails app with several nested forms. The user can add new records to, or delete records from, the nested forms dynamically. (Thanks Railscast #197).

The problem is that the user must submit the form for those changes to "stick". And that's not always obvious. For example, the user deletes a record from one nested form, and with the magic of jQuery it disappears from the page. But it's not really gone until the user clicks the "Update" button way at the bottom of the page. If he navigates away from the page, or uses the "Back" button, the changes are los开发者_JAVA技巧t.

My question is, how can I enforce the update: either automatically submitting the form when the user navigates away, or by notifying the user before he does so?

Thanks


You can intercept the page before the user leaves this way:

window.onbeforeunload = function(){
   alert("no, don't do it!");
   return false
})


If you have the option to save automatically, I'd say use that. It's slick, it's user-friendly and fairly easy to implement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜