4 public function setValue($value, $refill=
false) {
5 if (is_array($value) && $this->cfg->uniqValue) {
6 parent::setValue(array_shift($value));
9 $value = $this->
addNew($value);
10 parent::setValue($value);
20 protected function addNew(array $values) {
21 $new = isset($values[
'new']) && is_array($values[
'new']) ? array_filter($values[
'new']) : null;
22 unset($values[
'new']);
23 if ($this->cfg->allowAdd && count($new) && is_array($new)) {
24 $dbList = $this->cfg->dbList;
25 if (is_array($dbList) && $dbList[
'table']) {
26 $tbl =
db::get(
'table', $dbList[
'table']);
29 $i18n = isset($dbList[
'i18nFields']) && $dbList[
'i18nFields'];
31 $field = substr($dbList[
'fields'], strlen($dbList[
'ident'])+1);
34 $exists = array_search($v, $list);
35 if ($exists ===
false) {
36 $row = $tbl->getRow();
38 $i18nRow = $row->getI18nRow();
39 $i18nRow->set($dbList[
'i18nFields'], $v);
41 $row->set($field, $v);
50 if (is_array($this->cfg->list))
51 $this->
addRule(
'in', array_keys($this->cfg->list));
57 public function to($type) {
58 $ret = parent::to($type);
60 if ($type ==
'html' && $this->cfg->mode ==
'edit') {
61 $ret =
'<span id="'.$this->id.
'Container">'.$ret.
'</span>';
63 $resp->addJs(
'jqueryui');
64 $resp->addJs(
'formAutocomplete');
65 $prm = $this->cfg->jsPrm;
66 $prm[
'name'] = $this->
id.
'[]';
67 $prm[
'nameNew'] = $this->
id.
'[new]';
68 $resp->blockJquery(
'$("#'.$this->
id.
'Container").formAutocomplete('.json_encode($prm).
');');
static htmlOut($val, $key=false)
static htmlDeOut($val, $key=false)
static get($type, $table, array $prm=array())