10 $widget =&
$field[
'widget'];
12 $attributes = array(
'class'=>$widget[
'class'],
'id'=>
$field[
'name']);
14 $attributes[
'multiple'] =
true;
15 $attributes[
'size'] = 5;
17 $options = $record->_table->getValuelist(
$field[
'vocabulary']);
18 if ( !isset( $options) ) $options = array();
19 $emptyOpt = array(
''=>df_translate(
'scripts.GLOBAL.FORMS.OPTION_PLEASE_SELECT',
"Please Select..."));
21 if ( $record and $record->val(
$field[
'name']) ){
22 if ( !@
$field[
'repeat'] and !isset($options[$record->strval(
$field[
'name'])]) ){
23 $opts[$record->strval(
$field[
'name'])] = $record->strval(
$field[
'name']);
24 }
else if ( @
$field[
'repeat'] ){
26 $vals = $record->val(
$field[
'name']);
27 if ( is_array($vals) ){
28 foreach ( $vals as $thisval){
29 if ( !isset($options[$thisval]) ){
30 $opts[$thisval] = $thisval;
36 foreach($options as $kopt=>$opt){
40 $el = $factory->addElement(
'select', $formFieldName, $widget[
'label'], $opts, $attributes );
43 if ( @
$field[
'vocabulary'] ){
47 if ( !is_a($rel,
'Dataface_Relationship') ){
48 throw new Exception(
"The relationship object for the vocabulary ".
$field[
'vocabulary'].
" could not be loaded.");
51 if ( !$rel->getDomainTable() ){
52 throw new Exception(
"The relationship object for the vocabulary ".
$field[
'vocabulary'].
" could not be loaded or the domain table could not be found");
56 $perms = $dtable->getPermissions();
57 if ( @$perms[
'new'] ){
67 if ( strpos($valfield,
'.') !==
false ) list($tmp, $valfield) = explode(
'.', $valfield);
68 if ( strpos($keyfield,
'.') !==
false ) list($tmp, $keyfield) = explode(
'.', $keyfield);
70 $jt->import(
'RecordDialog/RecordDialog.js');
73 $suffix =
'<a href="#" onclick="return false" id="'.htmlspecialchars(
$field[
'name']).
'-other">Other..</a>';
75 jQuery(document).ready(function($){
76 $("#'.$field[
'name'].
'-other").each(function(){
77 var tablename = "'.addslashes($dtable->tablename).
'";
78 var valfld = '.json_encode($valfield).
';
79 var keyfld = '.json_encode($keyfield).
';
80 var fieldname = '.json_encode(
$field[
'name']).
';
82 $(this).RecordDialog({
84 callback: function(data){
85 var key = data[keyfld];
86 var val = data[valfld];
87 $("#"+fieldname).append(\'<option value="\'+key+\'">\'+val+\'</option>\');
88 $("#"+fieldname).val(key);
96 $widget[
'suffix'] = $suffix;
102 }
catch (Exception $ex){
103 error_log($ex->getMessage());
115 $table =& $record->_table;
121 $val = $element->getValue();
123 if ( count($val)>0 ){
131 return $element->getValue();