1
1
( function ( $ ) {
2
2
var OTHER_CHOICE = '__other__' ; //See
3
3
$ ( function ( ) {
4
- var wrappers = $ ( '.choice_with_other_wrapper' ) ;
5
- wrappers . each ( function ( ) {
6
- var select = $ ( 'select' , this ) ;
7
- var text_input = $ ( 'input' , this ) ;
8
- select . change ( function ( ) {
9
- if ( select . val ( ) == OTHER_CHOICE ) {
10
- ;
11
- } else {
12
- text_input . val ( select . val ( ) ) ;
4
+ $ ( 'body' ) . delegate ( '.choice_with_other_wrapper select' , 'change' , function ( e ) {
5
+ var select = $ ( this )
6
+ var text_input = $ ( this ) . parent ( ) . find ( 'input' )
7
+ if ( select . val ( ) == OTHER_CHOICE ) {
8
+ ;
9
+ } else {
10
+ text_input . val ( select . val ( ) ) ;
11
+ }
12
+ } ) ;
13
+ var text_input = $ ( 'input' , this ) ;
14
+ $ ( 'body' ) . delegate ( '.choice_with_other_wrapper input' , 'keyup' , function ( e ) {
15
+ var match = false ;
16
+ var text_input = $ ( this )
17
+ var select = $ ( this ) . parent ( ) . find ( 'select' )
18
+ $ ( select ) . find ( 'option' ) . each ( function ( ) {
19
+ if ( $ ( this ) . attr ( 'value' ) == text_input . val ( ) ) {
20
+ match = true ;
13
21
}
14
- } ) ;
15
- text_input . keyup ( function ( ) {
16
- var match = false ;
17
- $ ( select ) . find ( 'option' ) . each ( function ( ) {
18
- if ( $ ( this ) . attr ( 'value' ) == text_input . val ( ) ) {
19
- match = true ;
20
- }
21
- } )
22
- if ( ! match ) {
23
- select . val ( OTHER_CHOICE ) ;
24
- } else {
25
- select . val ( text_input . val ( ) ) ;
26
- }
27
- } ) ;
28
- select . change ( ) ;
22
+ } )
23
+ if ( ! match ) {
24
+ select . val ( OTHER_CHOICE ) ;
25
+ } else {
26
+ select . val ( text_input . val ( ) ) ;
27
+ }
28
+ } )
29
+
30
+ $ ( '.choice_with_other_wrapper' ) . each ( function ( ) {
31
+ $ ( 'select' , this ) . change ( ) ;
29
32
} )
33
+
30
34
} )
31
- } ) ( django . jQuery ) ;
35
+ } ) ( django . jQuery ) ;
0 commit comments