Skip to content

Commit 2b1c2b4

Browse files
author
Kim Godard
committed
Keep script from clobbering existing field values on initial load
If you're adding this to a form with fields that are already populated with values, this modification will keep the script from deleting your field values. :)
1 parent 3c4df4a commit 2b1c2b4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

demo/scripts/jquery.FloatLabel.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
label = element.find('label'),
1515
input = element.find('textarea, input');
1616

17-
input.val( label.text() );
17+
if( input.val() == '' ) {
18+
input.val( label.text() );
19+
} else {
20+
element.addClass( settings.populatedClass );
21+
}
1822

1923
input.on( 'focus', function(){
2024
element.addClass( settings.focusedClass );
@@ -45,4 +49,4 @@
4549

4650
};
4751

48-
})( jQuery );
52+
})( jQuery );

jquery.FloatLabel.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
label = element.find('label'),
1515
input = element.find('textarea, input');
1616

17-
input.val( label.text() );
17+
if( input.val() == '' ) {
18+
input.val( label.text() );
19+
} else {
20+
element.addClass( settings.populatedClass );
21+
}
1822

1923
input.on( 'focus', function(){
2024
element.addClass( settings.focusedClass );
@@ -45,4 +49,4 @@
4549

4650
};
4751

48-
})( jQuery );
52+
})( jQuery );

0 commit comments

Comments
 (0)