Permalink
Browse files

ENHANCEMENT Replaced Prototype show/hide functionality in ConfirmedPa…

…sswordField with jQuery. Added additional test case for show/hide markup.
  • Loading branch information...
1 parent 06089ed commit 9ea7e6899a59227e4c69e6fc8cbdf2848b3d412f Julian Seidenberg committed with chillu Feb 25, 2011
@@ -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;
+}
@@ -94,10 +94,9 @@ function __construct($name, $title = null, $value = "", $form = null, $showOnCli
}
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 = '';
@@ -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));
- }
-
- }
-});
+(function ($) {
+ $('.confirmedpassword .showOnClick a').live('click', function () {
+ $('.showOnClickContainer', $(this).parent()).toggle('fast');
+ return false;
+ });
+})(jQuery);
@@ -14,4 +14,18 @@ function testSetValue() {
$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");
+ }
}

0 comments on commit 9ea7e68

Please sign in to comment.