11/*
2- * jQuery Repeatable Fields v1.2
2+ * jQuery Repeatable Fields v1.3.0
33 * http://www.rhyzz.com/repeatable-fields.html
44 *
5- * Copyright (c) 2014 Rhyzz
5+ * Copyright (c) 2015 Rhyzz
66 * License MIT
77*/
88
4040$ ( this ) . prop ( 'disabled' , true ) ;
4141} ) ;
4242
43- var row_count = 1 ;
43+ var row_count = $ ( container ) . children ( settings . row ) . filter ( function ( ) {
44+ return ! $ ( this ) . hasClass ( settings . template . replace ( '.' , '' ) ) ;
45+ } ) . length ;
4446
45- $ ( container ) . children ( settings . row ) . each ( function ( ) {
46- if ( $ ( this ) . hasClass ( settings . template . replace ( '.' , '' ) ) === true ) {
47- return true ;
48- }
49-
50- var current_row_count = $ ( this ) . data ( 'rf-row-count' ) ;
51-
52- $ ( this ) . attr ( 'data-rf-row-count' , row_count ) ;
53-
54- row_count ++ ;
55- } ) ;
47+ $ ( container ) . attr ( 'data-rf-row-count' , row_count ) ;
5648
5749$ ( wrapper ) . on ( 'click' , settings . add , function ( event ) {
5850event . stopImmediatePropagation ( ) ;
10597}
10698
10799function after_add ( container , new_row ) {
108- var row_count ;
109-
110- $ ( new_row ) . parent ( settings . container ) . children ( settings . row ) . each ( function ( ) {
111- if ( $ ( this ) . hasClass ( settings . template . replace ( '.' , '' ) ) === true ) {
112- return true ;
113- }
114-
115- var current_row_count = $ ( this ) . data ( 'rf-row-count' ) ;
100+ var row_count = $ ( container ) . attr ( 'data-rf-row-count' ) ;
116101
117- if ( typeof current_row_count === 'undefined' ) {
118- var current_row_count = $ ( container ) . children ( settings . row ) . filter ( function ( ) {
119- return ! $ ( this ) . hasClass ( settings . template . replace ( '.' , '' ) ) ;
120- } ) . length ;
121- }
122- else {
123- current_row_count ++ ;
124- }
125-
126- if ( typeof row_count === 'undefined' || current_row_count > row_count ) {
127- row_count = current_row_count ;
128- }
129-
130- } ) ;
131-
132- $ ( new_row ) . attr ( 'data-rf-row-count' , row_count ) ;
102+ row_count ++ ;
133103
134104$ ( '*' , new_row ) . each ( function ( ) {
135105$ . each ( this . attributes , function ( index , element ) {
136106this . value = this . value . replace ( / { { row-c o u n t - p l a c e h o l d e r } } / , row_count - 1 ) ;
137107} ) ;
138108} ) ;
109+
110+ $ ( container ) . attr ( 'data-rf-row-count' , row_count ) ;
139111}
140112}
141113} ) ( jQuery ) ;
0 commit comments