Skip to content

Instantly share code, notes, and snippets.

@paulanthonywilson
Created July 23, 2009 11:00
Show Gist options
  • Save paulanthonywilson/152734 to your computer and use it in GitHub Desktop.
Save paulanthonywilson/152734 to your computer and use it in GitHub Desktop.
function bind_label_hiding(){
$("div.feedback_row label").each(function(index, item){
var field = $("#" + $(item).attr("for"));
field.bind("focus", function(){
$(item).hide();
});
field.bind("blur", function(){
if (jQuery.trim(field.attr("value")) == "") $(item).show();
});
if (jQuery.trim(field.attr("value")) != "") $(item).hide();
});
}
function attach_feedback_ujs(){
// bind_label_hiding();
bind_tab_activation();
}
describe("FeedbackLabelHiding", function(){
describe("on load ", function(){
before(function(){
$("#labeltext1").show();
});
describe("with no text entered ", function(){
it("should not hide the label", function(){
$("#text1").attr("value", "");
attach_feedback_ujs();
expect($("#labeltext1")).to(be_visible);
});
});
describe("with text entered ", function(){
it("should hide the label", function(){
$("#text1").attr("value", "hi");
attach_feedback_ujs();
expect($("#labeltext1")).to_not(be_visible);
});
});
describe("with empty string entered ", function(){
it("should not hide the label", function(){
$("#text1").attr("value", " ");
attach_feedback_ujs();
expect($("#labeltext1")).to(be_visible);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment