Php 为什么我输入的值在失去焦点时总是消失?

Php 为什么我输入的值在失去焦点时总是消失?,php,google-cloud-platform,combobox,Php,Google Cloud Platform,Combobox,我不擅长PHP 我有一个组合框,其中包含SQL查询中的下拉选项。每当我键入列表中没有的内容,然后将焦点切换到另一个对象时,我以前在该组合框中键入的内容总是消失。 但如果我键入的值包含在options/dropwdown列表中,则不会发生这种情况 如何使我在组合框中键入的任何内容不消失?如何获得它的价值 以下是创建组合框的脚本: $form->addField("artikel", "artikel", "combobox", [

我不擅长PHP

我有一个组合框,其中包含SQL查询中的下拉选项。每当我键入列表中没有的内容,然后将焦点切换到另一个对象时,我以前在该组合框中键入的内容总是消失。 但如果我键入的值包含在options/dropwdown列表中,则不会发生这种情况

如何使我在组合框中键入的任何内容不消失?如何获得它的价值

以下是创建组合框的脚本:

$form->addField("artikel", "artikel", "combobox", [
    "valueField"     => "ARTIKEL",
    "labelField"     => "ARTIKEL",
    "searchField"    => "ARTIKEL",
    "initialize"     => "load_Artikel",
    "placeholder"    => "",
    "label"          => "Artikel",
    "required"       => true,
    "onChange"       => "change_KDPenerimaan",
    "required_error" => "Article is required"
]);
这就是功能:

function addField($id, $name, $type, $options = array())
{
    $value = isset($options["value"]) ? $options["value"] : "";
    $placeholder = isset($options["placeholder"]) ? $options["placeholder"] : "";
    $required = isset($options["required"]) ? $options["required"] : false;
    $required_error = isset($options["required_error"]) ? $options["required_error"] : "";
    $label = isset($options["label"]) ? $options["label"] : "";
    if ($type == "general" || $type == "textarea" || $type == "number" || $type == "date") {
        $newfield = new InputForm_Field($id, $name, $type, $value, $label, $placeholder, $required, $required_error);
        if (isset($options['maxLength'])) {
            $newfield->setMaxLength($options["maxLength"]);
        }
    } else {
        if ($type == "hidden") {
            $newfield = new InputForm_Field($id, $name, $type, $value);
        } else {
            if ($type == "label") {
                $newfield = new InputForm_Field($id, $name, $type, $value, $label);
            } else {
                if ($type == "listbox") {
                    $keyField = isset($options["keyField"]) ? $options["keyField"] : "0";
                    $textField = isset($options["textField"]) ? $options["textField"] : "1";
                    $newfield = new InputForm_Field_ListBox($id, $name, $options["listType"], $keyField, $textField,
                        $options["options"], $value, $label,
                        $placeholder, $required, $required_error);
                    if (isset($options['listEmpty'])) {
                        $newfield->setListEmpty($options["listEmpty"]);
                    }
                } else {
                    if ($type == "combobox" || $type == "autocomplete") {
                        $newfield = new InputForm_Field_Combobox($id, $name, $type, $options);
                    } else {
                        if ($type == "radio") {
                            $newfield = new InputForm_Field_Radio($id, $name, $options["options"], $value, $label,
                                $required, $required_error);
                        } else {
                            if ($type == "inputbutton") {
                                $onClick = isset($options["onClick"]) ? $options["onClick"] : "";
                                $newfield = new InputForm_Field_InputButton($id, $name, $options["icon"], $onClick,
                                    $value, $label, $placeholder, $required, $required_error);
                            } else {
                                if ($type == "file") {
                                    $buttonText = isset($options["buttonText"]) ? $options["buttonText"] : "Select File";
                                    $newfield = new InputForm_Field_File($id, $name, $buttonText, $label, $required,
                                        $required_error);
                                    $newfield->setUploadParams($options["account"], $options["folderId"]);
                                    $newfield->setMultipleFiles(isset($options["multiple"]) ? $options["multiple"] : true);
                                    $this->upload = true;
                                } else {
                                    if ($type == "tagging") {
                                        $newfield = new InputForm_Field_Tagging($id, $name, $options);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (isset($options["readonly"])) {
        $newfield->readonly = $options["readonly"];
    }
    if (isset($options["disabled"])) {
        $newfield->disabled = $options["disabled"];
    }
    if (isset($options["customDraw"])) {
        $newfield->setCustomDraw($options["customDraw"]);
    }
    if (isset($options['customValidation'])) {
        $newfield->setCustomValidation($options["customValidation"]);
    }
    $this->fields[$id] = $newfield;
}
这是一节课:

class InputForm_Field_Combobox extends InputForm_Field
{
    public $createFunction;
    public $loadFunction;
    public $renderFunction;
    public $valueField;
    public $searchField;
    public $labelField;
    public $initialize;
    public $onChange;
    public $filterFunction;
    public $sortField;
    public $customValidation;
    public $groupBy;
    public $groupValues;

    function __construct($id, $name, $type = "combobox", $options = array())
    {
        $this->type = $type;
        if ($this->type !== "autocomplete") {
            $comboType = isset($options["tagging"]) && $options["tagging"] == true ? "combotagging" : "combobox";
        } else {
            $comboType = "autocomplete";
        }
        $value = isset($options["value"]) ? $options["value"] : "";
        $label = isset($options["label"]) ? $options["label"] : "";
        $placeholder = isset($options["placeholder"]) ? $options["placeholder"] : "";
        $required = isset($options["required"]) ? $options["required"] : "";
        $required_error = isset($options["required_error"]) ? $options["required_error"] : "";
        parent::__construct($id, $name, $comboType, $value, $label, $placeholder, $required, $required_error);
        if (isset($options["createFunction"])) {
            $this->createFunction = $options["createFunction"];
        }
        if (isset($options["loadFunction"])) {
            $this->loadFunction = $options["loadFunction"];
        }
        if (isset($options["renderFunction"])) {
            $this->renderFunction = $options["renderFunction"];
        }
        if (isset($options["filterFunction"])) {
            $this->filterFunction = $options["filterFunction"];
        }
        if (isset($options["valueField"])) {
            $this->valueField = $options["valueField"];
        }
        if (isset($options["default"])) {
            $this->default = $options["default"];
        }
        if (isset($options["searchField"])) {
            $this->searchField = $options["searchField"];
        }
        if (isset($options["labelField"])) {
            $this->labelField = $options["labelField"];
        }
        if (isset($options["initialize"])) {
            $this->initialize = $options["initialize"];
        }
        if (isset($options["onChange"])) {
            $this->onChange = $options["onChange"];
        }
        if (isset($options["sortField"])) {
            $this->sortField = $options["sortField"];
        }
        if (isset($options["customValidation"])) {
            $this->customValidation = $options["customValidation"];
        }
        if (isset($options["groupBy"])) {
            $this->groupBy = $options["groupBy"];
            $this->groupValues = $options["groupValues"];
        }
    }

    public function render()
    {
        $valueField = (isset($this->valueField)) ? ', valueField: ' . json_encode($this->valueField) : "";
        $searchField = (isset($this->searchField)) ? ', searchField: ' . json_encode($this->searchField) : "";
        $labelField = (isset($this->labelField)) ? ', labelField: ' . json_encode($this->labelField) : "";
        $createFunction = (isset($this->createFunction)) ? ', createFunction: ' . $this->createFunction : "";
        $loadFunction = (isset($this->loadFunction)) ? ', loadFunction: ' . $this->loadFunction : "";
        $renderFunction = (isset($this->renderFunction)) ? ', renderFunction: ' . $this->renderFunction : "";
        $filterFunction = (isset($this->filterFunction)) ? ', filterFunction: ' . $this->filterFunction : "";
        $default = "";
        if (isset($this->default)) {
            if (is_array($this->default)) {
                $default = ', f_default: ' . json_encode($this->default);
            } else {
                $default = ', f_default: "' . $this->default . '"';
            }
        }
        $onInitialize = (isset($this->initialize)) ? ', onInitialize: ' . $this->initialize : "";
        $customDraw = (isset($this->customDraw)) ? ', f_onDraw: ' . $this->customDraw : "";
        $onChange = (isset($this->onChange)) ? ', changeFunction: ' . $this->onChange : "";
        $customValidation = (isset($this->customValidation)) ? ', f_funcvalidate: ' . $this->customValidation : "";
        $groups = isset($this->groupBy) ? ', groupBy: "' . $this->groupBy . '", groupValues: ' . json_encode($this->groupValues) : "";

        $readonly = ($this->readonly == true) ? ', f_readonly: true' : "";
        $disabled = ($this->disabled == true) ? ', f_disabled: true' : "";
        if (is_array($this->value)) {
            $value = json_encode($this->value);
        } else {
            $value = '"' . $this->value . '"';
        }
        return '{f_id:"' . $this->id . '", f_name: "' . $this->name . '", f_type: "' . $this->type . '", f_value: ' . $value
            . ', f_placeholder: "' . $this->placeholder . '", f_label: "' . $this->label . '"'
            . ($this->required == true ? ', f_required: true, errorMessage: "' . $this->required_error . '"' : "")
            . $customDraw . $readonly . $disabled . $default . $valueField . $searchField . $labelField . $filterFunction . $createFunction . $loadFunction . $renderFunction
            . $customValidation . $onInitialize . $onChange . $groups . '},';
    }

    public function getScript($elem = "")
    {
        $sign = $elem != "" ? $elem : '$("#' . $this->id . '")';
        if (isset($this->sortField)) {
            $sort = "";
            if (is_array($this->sortField)) {
                foreach ($this->sortField as $srt) {
                    $sort .= '{field: "' . $srt . '", direction: "asc"},';
                }
                $sort = substr($sort, 0, strlen($sort) - 1);
            } else {
                $sort = '{field: "' . $this->sortField . '", direction: "asc"}';
            }
        } else {
            $sort = '{field: "' . $this->labelField . '", direction: "asc"}';
        }
        $this->script =
            $sign . '.selectize({'
            . (isset($this->valueField) ? 'valueField: "' . $this->valueField . '",' : "")
            . (isset($this->labelField) ? 'labelField: "' . $this->labelField . '",' : "")
            . (isset($this->searchField) ? 'searchField: "' . $this->searchField . '",' : "")
            . (isset($this->createFunction) ? 'create: ' . $this->createFunction . ',' : "")
            . (isset($this->loadFunction) ? 'load: ' . $this->loadFunction . ',' : "")
            . (isset($this->renderFunction) ? 'render: ' . $this->renderFunction . ',' : "")
            . (isset($this->initialize) ? 'onInitialize: ' . $this->initialize . ',' : "")
            . (isset($this->onChange) ? 'onChange: ' . $this->onChange . ',' : "")
            . (isset($this->groupBy) ? 'optgroupField: "' . $this->groupBy . '", optgroups: ' . json_encode($this->groupValues) . "," : "")
            . 'sortField: [' . $sort . '], dropdownParent: "body",'
            . (isset($this->filterFunction) ? 'createFilter: ' . $this->filterFunction . ',' : "")
            . 'maxItems: 1
                });';
        if (isset($this->value) && is_array($this->value) && count($this->value > 0)) {
            $this->script .= '
                var option = {};
                option["' . $this->valueField . '"] = "' . (isset($this->value[0]) ? $this->value[0] : "") . '";
                option["' . $this->labelField . '"] = "' . (isset($this->value[1]) ? $this->value[1] : "") . '";';
            if (isset($this->value[2])) {
                $customcriteria = $this->value[2];
                foreach ($customcriteria as $key => $custom) {
                    $this->script .= 'option["' . $key . '"] = "' . $custom . '";';
                }
            }
            $this->script .= $sign . '[0].selectize.addOption(option);' . "\n";
            $this->script .= $sign . '[0].selectize.setValue("' . (isset($this->value[0]) ? $this->value[0] : "") . '",true);' . "\n";
        }
        if ($this->readonly == true) {
            $this->script .= $sign . '.find(".selectize-input input").prop("readonly","readonly");';
        }
        return $this->script;
    }

    public function renderInput()
    {
        if (is_array($this->value)) {
            $value = isset($this->value[0]) ? $this->value[0] : "";
        } else {
            $value = $this->value;
        }
        if ($this->type == "combobox") {
            return '<select old-value="' . $value . '" placeholder="' . $this->placeholder . '"  id="' . $this->id . '" name="'
                . $this->name . '" class="' . ($this->idAsClass == true ? $this->id : "") . ' selectize" value="' . $value . '"'
                . ($this->disabled ? ' disabled' : '')
                . '></select><p class="error error_' . $this->id . '" style="display:none"></p>';
        } else {
            if ($this->type == "autocomplete") {
                return '<input old-value="' . $value . '" type="text" placeholder="' . $this->placeholder . '" id="' . $this->id . '" name="'
                    . $this->name . '" class="' . ($this->idAsClass == true ? $this->id : "") . ' selectize" value="' . $value . '"'
                    . ($this->disabled ? ' disabled' : '')
                    . '><p class="error error_' . $this->id . '" style="display:none"></p>';
            }
        }
    }
}
class InputForm\u Field\u组合框扩展了InputForm\u字段
{
公共功能;
公共$loadFunction;
公共$renderFunction;
公共价值场;
公共领域;
公共部门:拉贝尔菲尔德;
公帑;;
公费$onChange;
公共$filterFunction;
公共部门$sortField;
公共验证;
公共$groupBy;
公共价值;
函数uu构造($id,$name,$type=“combobox”,$options=array())
{
$this->type=$type;
如果($this->type!=“自动完成”){
$comboType=isset($options[“tagging”])和&$options[“tagging”]==true?“combotagging”:“combobox”;
}否则{
$comboType=“自动完成”;
}
$value=isset($options[“value”])?$options[“value”]:“”;
$label=isset($options[“label”])?$options[“label”]:“”;
$placeholder=isset($options[“placeholder”])?$options[“placeholder”]:“”;
$required=isset($options[“required”])?$options[“required”]:“”;
$required_error=isset($options[“required_error”])?$options[“required_error”]:“”;
父项::__构造($id、$name、$comboType、$value、$label、$placeholder、$required、$required_错误);
if(isset($options[“createFunction”])){
$this->createFunction=$options[“createFunction”];
}
如果(isset($options[“loadFunction”])){
$this->loadFunction=$options[“loadFunction”];
}
if(isset($options[“renderFunction”])){
$this->renderFunction=$options[“renderFunction”];
}
如果(isset($options[“filterFunction”])){
$this->filterFunction=$options[“filterFunction”];
}
如果(设置($options[“valueField”])){
$this->valueField=$options[“valueField”];
}
如果(isset($options[“default”])){
$this->default=$options[“default”];
}
如果(isset($options[“searchField”])){
$this->searchField=$options[“searchField”];
}
如果(isset($options[“labelField”])){
$this->labelField=$options[“labelField”];
}
如果(isset($options[“initialize”])){
$this->initialize=$options[“initialize”];
}
如果(isset($options[“onChange”])){
$this->onChange=$options[“onChange”];
}
如果(isset($options[“sortField”])){
$this->sortField=$options[“sortField”];
}
如果(isset($options[“customValidation”])){
$this->customValidation=$options[“customValidation”];
}
如果(isset($options[“groupBy”])){
$this->groupBy=$options[“groupBy”];
$this->groupValues=$options[“groupValues”];
}
}
公共职能
{
$valueField=(isset($this->valueField))?',valueField:'。json_encode($this->valueField):“”;
$searchField=(isset($this->searchField))?',searchField:'。json_encode($this->searchField):“”;
$labelField=(isset($this->labelField))?',labelField:'。json_encode($this->labelField):“”;
$createFunction=(isset($this->createFunction))?',createFunction:'。$this->createFunction:';
$loadFunction=(isset($this->loadFunction))?',loadFunction:'。$this->loadFunction:';
$renderFunction=(isset($this->renderFunction))?',renderFunction:'。$this->renderFunction:';
$filterFunction=(isset($this->filterFunction))?',filterFunction:'。$this->filterFunction:';
$default=“”;
if(设置($this->default)){
if(是_数组($this->default)){
$default=',f_default:'.json_encode($this->default);
}否则{
$default=',f_default:“。$this->default.”;
}
}
$onInitialize=(isset($this->initialize))?',onInitialize:'。$this->initialize:';
$customDraw=(isset($this->customDraw))?',f_onDraw:'。$this->customDraw:';
$onChange=(isset($this->onChange))?',changeFunction:'。$this->onChange:';
$customValidation=(isset($this->customValidation))?',f_funcvalidate:'。$this->customValidation:';
$groups=isset($this->groupBy)?”,groupBy:“。$this->groupBy.”,groupValues:“。json_encode($this->groupValues):”;
$readonly=($this->readonly==true)?,f_readonly:true':“”;
$disabled=($this->disabled==true)?,f_disabled:true':“”;
if(是_数组($this->value)){
$value=json_encode($this->value);
}否则{
$value=''“。$this->value''”;
}
返回“{f_id:”.$this->id.”,f_name:“.$this->name.”,f_type:“.$this->type.”,f_value:“.$value.”
,f_占位符:“'.$this->placeholder.”,f_标签:“'.$this->label.”
.($this->required==true?',f_required:true,errorMessage:“'.$this->required_error.'”:“”)
.$customDraw.$readonly.$disabled.$default.$valueField.$searchField.$labelField.$filterFunction.$createFunction.$loadFunction.$renderFunction
.$customValidation.$onInitialize.$onChange.$groups.'}';
}
公共函数getScript($elem=”“)
{
$sign=$elem!=''?$elem:'$(“#”)。$this->id。