CC-3093: SoundCloud preferences do not have email or password as required fields + firefox auto-fills the password field

I just realized this:
1. Enable "Enable Soundcloud Upload" in preference and fill in the username+password, click save
2. Go back to preference, change unrelated setting like "Station Name", click save
3. Now since soundcloud password field is empty (expected, as we don't want others to see how many digits
are there), the save failed

This commit is to fix this. Created another custom validator for the password field, which does the same
thing as ConditionalNotEmpty validator but allow password field to be empty when the username/email field
wasn't changed.
This commit is contained in:
Yuchen Wang 2011-11-24 15:45:39 -05:00
parent ee3a6ecd84
commit 485a0e8cc6
2 changed files with 20 additions and 1 deletions

View File

@ -1,5 +1,6 @@
<?php <?php
require_once 'customvalidators/ConditionalNotEmpty.php'; require_once 'customvalidators/ConditionalNotEmpty.php';
require_once 'customvalidators/PasswordNotEmpty.php';
class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm
{ {
@ -76,7 +77,7 @@ class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm
// which is something we don't want // which is something we don't want
'allowEmpty' => false, 'allowEmpty' => false,
'validators' => array( 'validators' => array(
new ConditionalNotEmpty(array('UploadToSoundcloudOption'=>'1')) new PasswordNotEmpty(array('UploadToSoundcloudOption'=>'1'))
) )
)); ));

View File

@ -0,0 +1,18 @@
<?php
class PasswordNotEmpty extends ConditionalNotEmpty {
public function isValid($value, $context = null)
{
$result = parent::isValid($value, $context);
if (!$result) {
// allow empty if username/email was set before and didn't change
$storedUser = Application_Model_Preference::GetSoundCloudUser();
if ($storedUser != '' && $storedUser == $context['SoundCloudUser']) {
return true;
}
}
return $result;
}
}
?>