This is a serious bug, because if a form field's value is not submitted, there is not any use for the Autocomplete.
Please fix it urgently:
Here is my code, the CodeIgniter Controller class:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of Admin
*
* @author michi
*/
class Admin extends Admin_controller{
//put your code here
public function __construct()
{
parent::__construct();
$this->load->helper('url_helper');
}
public function index()
{
//$data['news'] = $this->news_model->get_news();
$data['title'] = 'DAF Dashboard for Administrators';
$this->load->view('templates/header', $data);
$this->load->view('admin/top_menu');
$this->load->view('admin/links');
$this->load->view('admin/index', $data);
$this->load->view('templates/footer');
}
public function sponsored_brands(){
$data['title'] = 'DAF Dashboard für Administratoren';
$this->load->model('brands_model');
$this->load->model('brands_sponsored_model');
$this->load->helper('url_helper');
$data['brands'] = $this->brands_model->get_brands();
//$data['brands_sponsored'] = $this->brands_model->get_brands();
$data['brands_sponsored'] = $this->brands_sponsored_model->get_all_sponsored_brands();
//$this->form_validation->set_rules('sponsored_brand', 'Brand', 'callback_check_brand');
//$this->form_validation->set_rules('txtBrand', 'Username', 'callback_username_check');
//$this->form_validation->set_rules('txtBrand', 'Brand', 'callback_check_brand['.$this->input->post('txtBrand').']');
$this->form_validation->set_rules('datetimepicker_von', 'Von-Datum', 'callback_check_date|callback_check_less_than['.$this->input->post('datetimepicker_bis').']');
$this->form_validation->set_rules('datetimepicker_bis', 'Bis-Datum', 'callback_check_date');
//$this->form_validation->set_rules('username', 'Username', array('required', array($this->brands_model, 'valid_brand')));
if ($this->form_validation->run() == FALSE){
// not all fields were filled in or the form is displayed for the first time
//$data['brand_error'] = $_POST['sponsored_brand'];
$this->load->view('templates/header', $data);
$this->load->view('admin/top_menu');
$this->load->view('admin/links');
$this->load->view('admin/sponsored_brands', $data);
$this->load->view('templates/footer');
} else {
// all fields were filled in, so we can authenticate the user
// need to validate the sponsored_brand
//$data['brand_error'] = $_POST['sponsored_brand'];
$this->load->view('templates/header', $data);
$this->load->view('admin/top_menu');
$this->load->view('admin/links');
$this->load->view('admin/sponsored_brands', $data);
$this->load->view('templates/footer');
}
}
public function check_date($str){
if(strlen($str) > 0){
// we have a string input, check if it is a correct date
if(preg_match("/\d{2}(\.|-)\d{2}(\.|-)\d{4}/", $str) == 1){
// matches the correct format
// now check if it is a valid date
$parts = explode(".", $str);
$time = strtotime($parts[1] . '/' . $parts[0] . '/' . $parts[2]);
if($time === FALSE){
$this->form_validation->set_message('check_date', 'Bitte gültiges {field} im Format tt.mm.jjjj eingeben.');
return FALSE;
} else {
return TRUE;
}
} else {
$this->form_validation->set_message('check_date', 'Bitte gültiges {field} im Format tt.mm.jjjj eingeben.');
return FALSE;
}
} else {
$this->form_validation->set_message('check_date', 'Bitte gültiges {field} im Format tt.mm.jjjj eingeben.');
return FALSE;
}
}
public function check_less_than($str1, $str2){
if(strlen($str1) > 0 and strlen($str2) > 0){
$parts1 = explode(".", $str1);
$time1 = strtotime($parts1[1] . '/' . $parts1[0] . '/' . $parts1[2]);
$parts2 = explode(".", $str2);
$time2 = strtotime($parts2[1] . '/' . $parts2[0] . '/' . $parts2[2]);
if($time1 > $time2){
$this->form_validation->set_message('check_less_than', 'Das Bis-Datum muss gleich oder später als das Von-Datum sein.');
return FALSE;
} else {
return TRUE;
}
} else {
}
}
public function check_brand($str){
if(strlen($str) == 0){
$this->form_validation->set_message('check_brand', 'Bitte Brand aus der Drop-Down-Liste wählen.');
return FALSE;
} else {
// test if $str exists in brand table
$this->load->model('brands_model');
$result = $this->brands_model->get_brand_by_name($str);
if(empty($result)){
$this->form_validation->set_message('check_brand', 'Bitte Brand aus der Drop-Down-Liste wählen.');
return FALSE;
} else {
return TRUE;
}
}
}
}
And here is my CodeIgniter view file:
<h2>Gesponsorte Brands</h2>
<?php
$this->load->helper('url');
$ABSOLUTE_PATH_TO_ASSETS = FCPATH . "assets/";
//$URL_TO_ASSETS = "http://127.0.0.1/ci/assets/";
$URL_TO_ASSETS = base_url() . "assets/";
//$URL_TO_ASSETS = "http://127.0.0.1/daf-dashboard/assets/";
//CODE FOR GRID SPONSORED BRANDS
require $ABSOLUTE_PATH_TO_ASSETS."KoolControls/KoolGrid/koolgrid.php";
require $ABSOLUTE_PATH_TO_ASSETS."KoolControls/KoolAjax/koolajax.php";
require $ABSOLUTE_PATH_TO_ASSETS."KoolControls/KoolGrid/ext/datasources/PDODataSource.php";
require $ABSOLUTE_PATH_TO_ASSETS."KoolControls/KoolGrid/ext/datasources/AdvancedArrayDataSource.php";
$koolajax->scriptFolder = $URL_TO_ASSETS . "KoolControls/KoolAjax";
$ds_sponsored_brands = new ArrayDataSource($brands_sponsored);
$grid_sponsored_brands = new KoolGrid("grid_actors");
$grid_sponsored_brands->scriptFolder = $URL_TO_ASSETS . "KoolControls/KoolGrid";
$grid_sponsored_brands->DataSource = $ds_sponsored_brands;
$grid_sponsored_brands->Localization->Load($ABSOLUTE_PATH_TO_ASSETS."KoolControls/KoolGrid/localization/de.xml");
$grid_sponsored_brands->styleFolder = "sunset";
$grid_sponsored_brands->Width = "360px";
$grid_sponsored_brands->Height = "300px";
$grid_sponsored_brands->PageSize = 15;
$grid_sponsored_brands->AjaxEnabled = true;
$grid_sponsored_brands->KeepRowStateOnRefresh = true;
$grid_sponsored_brands->AllowScrolling = true;
$column = new GridBoundColumn();
$column->DataField = "brand_id";
$column->HeaderText = "ID";
$column->Width = "10%";
$grid_sponsored_brands->MasterTable->AddColumn($column);
$column = new GridBoundColumn();
$column->DataField = "brand_name";
$column->HeaderText = "Name";
$column->Width = "40%";
$grid_sponsored_brands->MasterTable->AddColumn($column);
$column = new GridBoundColumn();
$column->DataField = "start_at";
$column->HeaderText = "Von";
$column->Width = "25%";
$grid_sponsored_brands->MasterTable->AddColumn($column);
$column = new GridBoundColumn();
$column->DataField = "end_at";
$column->HeaderText = "Bis";
$column->Width = "25%";
$grid_sponsored_brands->MasterTable->AddColumn($column);
$grid_sponsored_brands->MasterTable->AllowHovering = true;
$grid_sponsored_brands->MasterTable->VirtualScrolling = true;
$grid_sponsored_brands->MasterTable->AllowSelecting = true;
$grid_sponsored_brands->MasterTable->AutoGenerateColumns = false;
$grid_sponsored_brands->MasterTable->AutoGenerateDeleteColumn = false;
$grid_sponsored_brands->MasterTable->AutoGenerateExpandColumn = false;
$grid_sponsored_brands->MasterTable->Width = "600px";
$grid_sponsored_brands->MasterTable->RowAlternative = true;
$grid_sponsored_brands->MasterTable->Pager = new GridPrevNextAndNumericPager();
$grid_sponsored_brands->ClientSettings->ClientEvents["OnRowClick"] = "Handle_OnRowClick_ActorsGrid";
$grid_sponsored_brands->Process();
// CODE FOR SELECT INPUT AUTOCOMPLETE BRANDS
require $ABSOLUTE_PATH_TO_ASSETS."KoolControls/KoolAutoComplete/koolautocomplete.php";
$kac = new KoolAutoComplete("kac");
$kac->scriptFolder = $URL_TO_ASSETS . "KoolControls/KoolAutoComplete";
$kac->width = "160px";
$kac->attachTo = "sponsored_brand";
$kac->styleFolder = "default";
foreach($brands AS $brand) {
//echo $brand['brand_name'] . '<br>';
$kac->addItem($brand['brand_name']);
}
$kac->searchFilter="startwith";
//CODE FOR DATEPICKER VON BIS
require $ABSOLUTE_PATH_TO_ASSETS."KoolControls/KoolCalendar/koolcalendar.php";
$datepicker_von = new KoolDatePicker("datetimepicker_von"); //Create calendar object
$datepicker_von->scriptFolder = $URL_TO_ASSETS."KoolControls/KoolCalendar";//Set scriptFolder
$datepicker_von->styleFolder="default";
//Change date and time format
$datepicker_von->DateFormat = "d.m.Y";
$datepicker_von->Init();
$datepicker_bis = new KoolDatePicker("datetimepicker_bis"); //Create calendar object
$datepicker_bis->scriptFolder = $URL_TO_ASSETS."KoolControls/KoolCalendar";//Set scriptFolder
$datepicker_bis->styleFolder="default";
//Change date and time format
$datepicker_bis->DateFormat = "d.m.Y";
$datepicker_bis->Init();
?>
<script type="text/javascript">
function Handle_OnRowClick_ActorsGrid(sender,args)
{
var _row = args["Row"];
var _res = document.getElementById("res");
var msg = "Latest event: Row with [ID = "+ _row.getDataItem()["actor_id"]+"] was selected";
alert(msg);
}
</script>
<span style="color: red;">
<?php
echo validation_errors();
?></span>
<?php $hidden = array('sponsored_brand_value' => 'abc'); echo form_open('admin/sponsored_brands', '', $hidden); ?>
<?php echo $koolajax->Render();?>
<?php echo $grid_sponsored_brands->Render();?>
<div style="float:left;width:450px;margin-bottom:30px;">
Brand:
<input type="text" id="sponsored_brand" autocomplete='off' style="width: 350px"/>
<?php echo $kac->Render();?>
Von:
<?php echo $datepicker_von->Render();?>
Bis:
<?php echo $datepicker_bis->Render();?>
<br/>
<?php echo form_submit('submit', 'Anzeige Anlegen'); ?>
</div>
<br style="clear:both;"/>
<div style="padding-top:10px;">
<?php
if($datepicker_von->Value!=null)
{
echo "<b>Von:</b> ".$datepicker_von->Value . "<br>";
}
if($datepicker_bis->Value!=null)
{
echo "<b>Bis:</b> ".$datepicker_bis->Value . "<br>";
}
?>
</div>
<?php echo form_close(); ?>
If I examine the pages source, then the field 'sponsored_brand' is there and the AutoComplete displays options as it should, but the form field does not get transmitted to the server.