File tree 1 file changed +22
-4
lines changed
1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 1
1
// Apache 2.0 J Chris Anderson 2011
2
2
$ ( function ( ) {
3
+ // friendly helper http://tinyurl.com/6aow6yn
4
+ $ . fn . serializeObject = function ( ) {
5
+ var o = { } ;
6
+ var a = this . serializeArray ( ) ;
7
+ $ . each ( a , function ( ) {
8
+ if ( o [ this . name ] ) {
9
+ if ( ! o [ this . name ] . push ) {
10
+ o [ this . name ] = [ o [ this . name ] ] ;
11
+ }
12
+ o [ this . name ] . push ( this . value || '' ) ;
13
+ } else {
14
+ o [ this . name ] = this . value || '' ;
15
+ }
16
+ } ) ;
17
+ return o ;
18
+ } ;
19
+
3
20
var path = unescape ( document . location . pathname ) . split ( '/' ) ,
4
21
design = path [ 3 ] ,
5
22
db = $ . couch . db ( path [ 1 ] ) ;
@@ -31,10 +48,11 @@ $(function() {
31
48
loggedIn : function ( r ) {
32
49
$ ( "#profile" ) . couchProfile ( r , {
33
50
profileReady : function ( profile ) {
34
- $ ( "#create-message" ) . submit ( function ( ) {
35
- var form = this , doc = { } ;
36
- doc . created_at = new Date ( ) ;
37
- doc . profile = profile ;
51
+ $ ( "#create-message" ) . submit ( function ( e ) {
52
+ e . preventDefault ( ) ;
53
+ var form = this , doc = $ ( form ) . serializeObject ( ) ;
54
+ doc . created_at = new Date ( ) ;
55
+ doc . profile = profile ;
38
56
db . saveDoc ( doc , { success : function ( ) { form . reset ( ) ; } } ) ;
39
57
return false ;
40
58
} ) . find ( "input" ) . focus ( ) ;
You can’t perform that action at this time.
0 commit comments