hi,
i am trying to generate a random string value when i open a new Object in ModelAdmin. (Create ObjectXY)
i use getCMSFields to remove the Field from the Tab, Generate a Random String and want to add the Field again with the Random Value.
but when i add the field again like that:
$f->addFieldToTab('Root.Main',new TextField('Code','PromoCode',$randomUniqueCode));
.. the textfield stays empty :(
here´s my full getCMSFields function:
function getCMSFields(){
$f = parent::getCMSFields();
$f->removeFieldFromTab('Root','Code');
//generate code first time
$randomUniqueCode = $this->generateRandomCode(10);
$existingCodes = DataObject::get('PromoCode');
if(count($existingCodes)){
foreach($existingCodes as $code){
if($randomUniqueCode == $code->Code)
$randomUniqueCode = $this->generateRandomCode(10);
else
break;
}
}
if($this->ID == 0)
$f->addFieldToTab('Root.Main',new TextField('Code','PromoCode',$randomUniqueCode));
else
$f->addFieldToTab('Root.Main',new TextField('Code','PromoCode',$this->Code));
return $f;
}
thanks for your help in advance
matze