mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Replaced Prototype show/hide functionality in ConfirmedPasswordField with jQuery. Added additional test case for show/hide markup.
This commit is contained in:
parent
06089eddfd
commit
9ea7e6899a
4
css/ConfirmedPasswordField.css
Normal file
4
css/ConfirmedPasswordField.css
Normal 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;
|
||||
}
|
@ -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 = '';
|
||||
|
||||
|
@ -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 @@ 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");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user