<?php
 namespace App\Form\Input; class Autocomplete_SupplierAndProduct extends Autocomplete_GeneralAbstract { protected $class = "autocomplete"; public function __construct($label=null, $name=null, $value=null) { parent::__construct($label, $name, $value); $this->url = \Engine\Mvc\Dispatcher::getInstance()->getAppUrl('Modules/RemoteData/AutocompleteFieldData', '', ['class'=>'SupplierAndProduct']); $this->setStyle('minimumTextLength', 2); } public function getValue() { $v = parent::getValue(); if ($v==='|') { $v = ''; } return $v; } protected function getTemplateParams($templateClass = null, $parentElement = null) { $params = parent::getTemplateParams($templateClass, $parentElement ); if ($this->value and !$this->displayValue) { list($idSupplier, $idSupplierProduct)=explode('|', $this->value); if ($idSupplierProduct) { $this->displayValue=\Entity\SupplierProduct::select($idSupplierProduct)->name; } else { $this->displayValue=\Entity\Supplier::select($idSupplier)->name; } $params['displayValue']=$this->displayValue; } return $params; } } 