IMPR: Minor placeholders updates

This commit is contained in:
Tony Air 2024-02-07 22:37:57 +02:00
parent 67b681e468
commit bf64366060
2 changed files with 39 additions and 10 deletions

View File

@ -4,6 +4,7 @@ namespace A2nt\CMSNiceties\Ajax\Ex;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\Form; use SilverStripe\Forms\Form;
@ -13,25 +14,52 @@ use SilverStripe\Security\Security;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
/** /**
* Class \App\Service\Ex\ServiceAreaController * Class \A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx
* *
* @property \A2nt\CMSNiceties\Ajax\Ex\AjaxLoginFormControllerEx $owner * @property \A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx $owner
*/ */
class AjaxControllerEx extends Extension class AjaxControllerEx extends Extension
{ {
private static $no_placeholders = false;
private static $show_labels = false;
private static $allowed_actions = [ private static $allowed_actions = [
'LoginFormEx', 'LoginFormEx',
'LostPasswordForm', 'LostPasswordForm',
'passwordsent', 'passwordsent',
]; ];
private static function _makeAllFieldsRequired(Form $form) private static function _processFields(Form $form)
{ {
$cfg = Config::inst()->get(__CLASS__);
$fields = $form->Fields(); $fields = $form->Fields();
foreach ($fields as $f) { foreach ($fields as $field) {
$f $name = $field->getName();
if ($name === 'Remember') {
continue;
}
$field
->setAttribute('required', 'required') ->setAttribute('required', 'required')
->addExtraClass('required'); ->addExtraClass('required');
/*
* A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx:
* show_labels: false
* no_placeholders: false
*/
if (!$cfg['no_placeholders']) {
$placeholder = $field->Title();
$field->setAttribute(
'placeholder',
$placeholder
);
}
if (!$cfg['show_labels']) {
$field->setTitle('');
}
} }
} }
@ -41,10 +69,10 @@ class AjaxControllerEx extends Extension
/* @var Form $form */ /* @var Form $form */
$form = $ctrl->LoginForm(); $form = $ctrl->LoginForm();
self::_makeAllFieldsRequired($form); self::_processFields($form);
//$form->addExtraClass('ajax-form'); //$form->addExtraClass('ajax-form');
$form->setLegend('Sign in to your service account'); $form->setLegend('Log in to your service account');
if ($form->get_protector()) { if ($form->get_protector()) {
$form->enableSpamProtection(); $form->enableSpamProtection();
@ -64,7 +92,7 @@ class AjaxControllerEx extends Extension
->getLostPasswordHandler($ctrl->Link()) ->getLostPasswordHandler($ctrl->Link())
->lostPasswordForm(); ->lostPasswordForm();
self::_makeAllFieldsRequired($form); self::_processFields($form);
$form->addExtraClass('ajax-form'); $form->addExtraClass('ajax-form');
$form->setLegend('Restore your password'); $form->setLegend('Restore your password');

View File

@ -29,8 +29,9 @@ class PlaceholderFormExtension extends Extension
if (is_a($field, TextField::class) || is_a($field, TextareaField::class)) { if (is_a($field, TextField::class) || is_a($field, TextareaField::class)) {
if (!$field->getAttribute('placeholder')) { if (!$field->getAttribute('placeholder')) {
$placeholder = $field->Title(); $placeholder = $field->Title();
$cfg = Config::inst()->get(\get_class($this->owner));
if (!Config::inst()->get(\get_class($this->owner), 'no_placeholders')) { if (!$cfg['no_placeholders']) {
$field->setAttribute( $field->setAttribute(
'placeholder', 'placeholder',
$placeholder $placeholder
@ -41,7 +42,7 @@ class PlaceholderFormExtension extends Extension
* SilverStripe\UserForms\Form\UserForm: * SilverStripe\UserForms\Form\UserForm:
* show_labels: false * show_labels: false
*/ */
if (!Config::inst()->get(\get_class($this->owner), 'show_labels')) { if (!$cfg['show_labels']) {
$field->setTitle(''); $field->setTitle('');
} }
} }