I created a CustomTextField and these includes work:
<?php
class CustomTextField extends TextField {
function __construct($name, $title = null, $value = "", $maxLength = null, $form = null){
$this->include_js($name);
parent::__construct($name, $title, $value, $maxLength, $form);
}
public static function include_js($name){
Requirements::javascript('productadmin/testcode/test.js'); // <--- works
}
function Field() {
$attributes = array(
'type' => 'text',
'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(),
'name' => $this->Name(),
'value' => $this->Value(),
'tabindex' => $this->getTabIndex(),
'maxlength' => ($this->maxLength) ? $this->maxLength : null,
'size' => ($this->maxLength) ? min( $this->maxLength, 30 ) : null
);
if($this->disabled) $attributes['disabled'] = 'disabled';
Requirements::javascript('productadmin/testcode/test.js'); // <--- works
return $this->createTag('input', $attributes);
}
}
The customScript in Field() does not work, but neither in ModelAdmin:
Requirements::customScript("var test = 'test';", 'UniqueID');