ENHANCEMENT Replaced Prototype show/hide functionality in ConfirmedPasswordField with jQuery. Added additional test case for show/hide markup.

This commit is contained in:
Julian Seidenberg 2011-02-25 17:01:46 +13:00 committed by Ingo Schommer
parent 06089eddfd
commit 9ea7e6899a
4 changed files with 26 additions and 29 deletions

View File

@ -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;
}

View File

@ -94,10 +94,9 @@ class ConfirmedPasswordField extends FormField {
} }
function Field() { function Field() {
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototype_improvements.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/ConfirmedPasswordField.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/ConfirmedPasswordField.js');
Requirements::css(SAPPHIRE_DIR . '/css/ConfirmedPasswordField.css');
$content = ''; $content = '';

View File

@ -1,26 +1,6 @@
Behaviour.register({ (function ($) {
'div.confirmedpassword' : { $('.confirmedpassword .showOnClick a').live('click', function () {
initialize: function() { $('.showOnClickContainer', $(this).parent()).toggle('fast');
var rules = {}; return false;
rules['#'+this.id+' .showOnClick a'] = {onclick: function(e) { });
this.toggle(); })(jQuery);
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));
}
}
});

View File

@ -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() . '[_Password]')->Value());
$this->assertEquals('valueB', $field->children->fieldByName($field->Name() . '[_ConfirmPassword]')->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");
}
} }