I built a combo in a form and filled with a connector as shown below. The problem comes when I save a value that is not listed in the combo. The form data is saved but not the new values entered manually in the combo.
How do I save a new value manually entered into a combo ?
Combo connector
<?php
require_once('config_areapec.php');
require_once('php/codebase/combo_connector.php');
$champ=$_GET["champ"];
$options = new ComboConnector($conn);
switch ($champ){
//test
case "nom":
$options->set_encoding("iso-8859-1");//sinon les accents dans la base font planter l'interface
$options->render_sql("SELECT distinct nom FROM test GROUP BY nom","nom","nom");
break;
}
?>
My form (extract)
//--- dhtmlXDataStore initialization. This dataStore is populated with data from DB ---
var convention = new dhtmlXDataStore({
url:"convention_test.php",
datatype:"xml"
});
//---data scheme. Sets a default scheme for adding data records---
convention.data.scheme({
id_convention:"",
etat:"test",
nom:""
});
//---dataProcessor initialization. We use dataProcessor to implement Create/Update/Delete operations---
myDP = new dataProcessor("convention_test.php");
myDP.init(convention);
//---layout initialization and configuration ---
var layout = new dhtmlXLayoutObject("box","2U");
layout.cells("a").setText("Liste des etats");
layout.cells("b").setText("Informations etats");
layout.cells("a").setWidth(400);
layout.cells("a").setHeight(50);
layout.cells("a").setWidth(400);
layout.cells("a").setHeight(50);
//layout.cells("a").attachObject("box");
//---grid initialization and configuration ---
myGrid = layout.cells("a").attachGrid();
myGrid.setImagePath("codebase/imgs/");
myGrid.setSkin("dhx_skyblue");
//myGrid.setColTypes("txt,dhxCalendarA");
myGrid.setHeader("Etat,Nom");
myGrid.setInitWidths("110,110");
myGrid.setColumnIds("etat,nom");
myGrid.setColTypes("ed,ed");
myGrid.init();
//---form initialization and configuration ---
var formData = [
{ type:"input",value:"", name:"etat", label:"Etat", width:100, labelWidth:"100", labelHeight:"21", inputWidth:"100", inputHeight:"21", labelLeft:"15", labelTop:"15", inputLeft:"15", inputTop:"36", position:"absolute"},
{ type:"combo" , name:"nom", label:"nom", width:175, labelWidth:"175", labelHeight:"21", inputWidth:"175", inputHeight:"21", labelLeft:"215", labelTop:"15", inputLeft:"150", inputTop:"36", position:"absolute",connector:"combo_perso_test.php?champ=nom" },
{ type:"button" , name:"save", label:"OK", value:"OK", width:"40", inputWidth:"250", inputHeight:"21", labelLeft:"-10", labelTop:"-10", inputLeft:"15", inputTop:"180", position:"absolute" },
{ type:"button" , name:"add", label:"Ajout", value:"Création", width:"80", inputWidth:"80", inputHeight:"21", labelLeft:"-10", labelTop:"-10", inputLeft:"150", inputTop:"180", position:"absolute" },
{ type:"button" , name:"delete", label:"Suppression", value:"Suppression", width:"80", inputWidth:"80", inputHeight:"21", labelLeft:"-10", labelTop:"-10", inputLeft:"289", inputTop:"180", position:"absolute" }
];
myForm = layout.cells("b").attachForm(formData);
//---binding the grid to the dataStore. Loading data from the dataStore to the grid---
myGrid.sync(convention);
//--- binding the form to the grid. Presenting record's details in the form ---
myForm.bind(myGrid);
//--- Create/Update/Delete operations ---
myForm.attachEvent("onButtonClick", function(id){
if (id=='add'){//
convention.add({}); //creates a new record that uses 'amc.data.scheme'
}
else if (id=='save'){
myForm.save(); //saves the made changes
}
else if (id=='delete'){ //deletes the selected row
var selectedItem = myGrid.getSelectedRowId();
convention.remove(selectedItem);
}
});