diff --git a/css/ConfirmedPasswordField.css b/css/ConfirmedPasswordField.css new file mode 100644 index 000000000..7abb120d5 --- /dev/null +++ b/css/ConfirmedPasswordField.css @@ -0,0 +1,4 @@ +.confirmedpassword .showOnClickContainer { + /* used to hide a container by-default when loading it so there is no "flash" as the content loads */ + display:none; +} \ No newline at end of file diff --git a/forms/ConfirmedPasswordField.php b/forms/ConfirmedPasswordField.php index 16ce49d63..e376c6dbb 100644 --- a/forms/ConfirmedPasswordField.php +++ b/forms/ConfirmedPasswordField.php @@ -94,10 +94,9 @@ class ConfirmedPasswordField extends FormField { } function Field() { - Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js'); - Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js'); - Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototype_improvements.js'); + Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/ConfirmedPasswordField.js'); + Requirements::css(SAPPHIRE_DIR . '/css/ConfirmedPasswordField.css'); $content = ''; diff --git a/javascript/ConfirmedPasswordField.js b/javascript/ConfirmedPasswordField.js index 948ebda1b..2a2451f00 100644 --- a/javascript/ConfirmedPasswordField.js +++ b/javascript/ConfirmedPasswordField.js @@ -1,26 +1,6 @@ -Behaviour.register({ - 'div.confirmedpassword' : { - initialize: function() { - var rules = {}; - rules['#'+this.id+' .showOnClick a'] = {onclick: function(e) { - this.toggle(); - Event.stop(e); - }.bind(this)}; - - Behaviour.register(rules); - - this.toggle(); - }, - - toggle: function() { - var containers = $$('.showOnClickContainer', this); - if(!containers.length) return false; - - var container = containers[0]; - Element.toggle(container); - var hiddenField = $$('input.hidden', this)[0]; - hiddenField.value = (Element.visible(container)); - } - - } -}); \ No newline at end of file +(function ($) { + $('.confirmedpassword .showOnClick a').live('click', function () { + $('.showOnClickContainer', $(this).parent()).toggle('fast'); + return false; + }); +})(jQuery); \ No newline at end of file diff --git a/tests/forms/ConfirmedPasswordFieldTest.php b/tests/forms/ConfirmedPasswordFieldTest.php index cb7be3b68..9887eb618 100644 --- a/tests/forms/ConfirmedPasswordFieldTest.php +++ b/tests/forms/ConfirmedPasswordFieldTest.php @@ -14,4 +14,18 @@ class ConfirmedPasswordFieldTest extends SapphireTest { $this->assertEquals('valueB', $field->children->fieldByName($field->Name() . '[_Password]')->Value()); $this->assertEquals('valueB', $field->children->fieldByName($field->Name() . '[_ConfirmPassword]')->Value()); } + + function testSetShowOnClick() { + //hide by default and display show/hide toggle button + $field = new ConfirmedPasswordField('Test', 'Testing', 'valueA', null, true); + $fieldHTML = $field->Field(); + $this->assertContains("showOnClickContainer",$fieldHTML,"Test class for hiding/showing the form contents is set"); + $this->assertContains("showOnClick",$fieldHTML,"Test class for hiding/showing the form contents is set"); + + //show all by default + $field = new ConfirmedPasswordField('Test', 'Testing', 'valueA', null, false); + $fieldHTML = $field->Field(); + $this->assertNotContains("showOnClickContainer",$fieldHTML,"Test class for hiding/showing the form contents is set"); + $this->assertNotContains("showOnClick",$fieldHTML,"Test class for hiding/showing the form contents is set"); + } }