Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Fix the way placeholder works.
Browse files Browse the repository at this point in the history
If there is a placeholder but NO label, the placeholder becomes the label.
If there is a placeholder AND a label, the placeholder becomes the title of the label (and thus shows up when you hover on the label).
  • Loading branch information
remybach committed Aug 15, 2012
1 parent bea3ae5 commit 48d8b59
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions jquery.superLabels.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
* Version: 1.1.0
* Version: 1.1.1
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
Expand Down Expand Up @@ -71,16 +71,20 @@
var _label = _getLabel(this);
var _placeholder = _field.attr('placeholder');

// Check for the placeholder attribute first.
// If there's a placeholder
if (_placeholder) {
var _placeholderLabel = $('<label for="'+(_field.attr('id') || _field.attr('name'))+'">'+_placeholder+'</label>');

// If there isn't a label for this field, create one, otherwise replace the existing one with the placeholder one.
// but NO label, make a label using the placeholder
if (_label.length === 0) {
var _placeholderLabel = '<label for="'+(_field.attr('id') || _field.attr('name'))+'">'+_placeholder+'</label>';
_placeholderLabel+= '</label>';
_placeholderLabel = $(_placeholderLabel);

// If there isn't a label for this field, create one, otherwise replace the existing one with the placeholder one.
_label = _placeholderLabel;
_field.prev(_label);
_field.before(_label);
} else {
_label.replaceWith(_placeholderLabel);
// Otherwise, just give the label a title with the placeholder
_label.attr('title', _placeholder);
}
_field.removeAttr('placeholder');
}
Expand Down

0 comments on commit 48d8b59

Please sign in to comment.