-
Hiding a DCA field
Hi all,
I'm attempting to hide the password boxes in tl_member when a checkbox is ticked. I see two approaches:
1) Add another database column called 'password_random'
or
2) Extend the Password widget to add a tickbox above the password boxes and hide when ticked.
The idea is that the user ticks 'Random Password' and then the password boxes will be greyed or hidden. The main problem so far is that since password is mandatory I've got to some how find a way to hide a DCA when ticked.
Any ideas?
-
Re: Hiding a DCA field
You can add a onload_callback() method that changes the dca. You can insert your new dca field as a checkbox with a submitOnChange=>true and in the subpalette.
-
Re: Hiding a DCA field
Sadly, some validation somewhere is stopping a blank password being saved. I've disabled the minlength and save_callback for password but it's still complaining about it requiring a min of 8 characters.
-
Re: Hiding a DCA field
That is part of the widget, not the DCA. There it checks the TL_CONFIG for the min password length, which you will have yo adjust in settings.
-
Re: Hiding a DCA field
A bit of a tricky one, don't really want to be altering the password length on the fly.
Also trying to un-necessarily re-implement parts of any core class such as the widget class.
I can possibly see some sort of extension of the Password widget and set some new attributes within the DCA.
Potentially if I use disabled as an attribute with a new 'PasswordEnhanced' class, override validator() and only call tha parent class when disabled isn't true.
EDIT:
Extending the Password class to PasswordExtend and adding
will allow the load_callback approach to editing the palettes to work. It's now just a case of setting the disabled variable within the widget. However any changed variables in the DCA do not seem to update the Widget.
EDIT2: I will experiment with adding a new callback method within the widget that is called within validator.
-
Re: Hiding a DCA field
The following works WITHOUT modifying the Password widget, I just hope this isn't a bug ;)
I will repackage this as a module in it's own right outside of the other module I'm developing it for.
Code:
/**
* Pointers
*/
$conf = &$GLOBALS['TL_DCA']['tl_member']['config'];
$fields = &$GLOBALS['TL_DCA']['tl_member']['fields'];
$palettes = &$GLOBALS['TL_DCA']['tl_member']['palettes'];
$subpalettes = &$GLOBALS['TL_DCA']['tl_member']['subpalettes'];
$lang = &$GLOBALS['TL_LANG']['tl_member'];
/**
* Configuration
*/
$conf['onload_callback'][] = array('tl_member_ef','password_toggle_load');
/**
* Fields
*/
$fields['password_random'] = array(
'label' => &$lang['password_random'],
'inputType' => 'checkbox',
'exclude' => true,
'eval' => array('submitOnChange'=>true),
'save_callback' => array(
array('tl_member_ef','password_toggle_save')
)
);
class tl_member_ef extends Backend{
public function password_toggle_load(DataContainer $dc){
$r=$this->Database->prepare('SELECT `password_random` FROM tl_member WHERE id=?')
->execute($dc->id);
$s = &$GLOBALS['TL_DCA']['tl_member']['subpalettes'];
if($r->password_random){
$s['login'] = str_replace('password_random,password','password_random',$s['login']);
}
}
public function password_toggle_save($value,DataContainer $dc){
$s = &$GLOBALS['TL_DCA']['tl_member']['subpalettes'];
if($value){
$GLOBALS['TL_DCA']['tl_member']['fields']['password']['eval']['disabled']=true;
$s['login'] = str_replace('password_random,password','password_random',$s['login']);
}
return $value;
}
}