This plugin observes values of form elements.
When end-user changes any values of input elements, observer shows which values were changed. And observer also alerts to users when they try to move out from the page before submitting changes.
Usage
You can add FormObserve plugin onto any form element.
$(document).ready(function(){
$('#MyForm').FormObserve();
});
<form id="MyForm">
<input type="text" value="here's default value" />
<input type="submit" value="save" />
</form>
If you want to show users the changes, you can add the definition of class 'changed'.
<style>
.changed {
background-color: red;
}
</style>
After changes have been completed (might be 'onsubmit', 'ajax complete' and so on), you should call FormObserve_save() method.
$('#MyForm').submit(function(){
if(validation=='ok'){
$(this).FormObserve_save();
}
});
You can change the class name of changed input-elements.
$(document).ready(function(){
$('#MyForm').FormObserve({changeClass: "alert-color");
});
Default value is 'changed'.
You can set the alert message.
Default value is "Unsaved changes will be lost.\nReally continue?"
You can call FormObserve_save() method to each elements.
$('#ajax-button').click(function(){
// after saving on server
$(this).FormObserve_save();
});
This plugin is very handy using with jGlycy.
<form jg="FormObserve">
<input type="text" value="here's default value" />
<input type="submit" value="save" />
</form>
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>popup</title> <meta http-equiv="Content-Type" content="text/html; charset=gbk2312" /> <script type="text/javascript" src="/ajax/popup.
Language Helpers page Source JavaScriptMVC has several lightweight language helper plugins. Object Methods useful for comparing Objects. For example, if two objects are thesame: $.Object.same({f
默认的情况下,Rails是使用Prototype 做为javascript 框架,如果我们想用 jQuery 来替换它,可以用如下方法 先来看一些对比的例子, jQuery能更好的实现代码从表现层分离 Prototype $('the-link').observe('click', function() { $('the-div').addClass('hello'); });
使用jQuery,你的RoR Application 可享有所有 Unobtrusive JavaScript 帶來的優點,使編碼和Markup絕對分開,又可以要最快的速度建立所有用戶端的功能和介面效果。 現在的 RoR + Prototype 方案,其中最大一個問題就是如何處理 ySlow 作者 Steve Souders 極度重視的 "Put CSS at top", "Put Javascr