From ce637ac75916fd78f8a05c7d76c97b84d243e34f Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 30 Sep 2015 16:06:15 +0000 Subject: [PATCH] Pass current selectbox value so the server can make sure it's there --- .../class.etemplate_widget_menupopup.inc.php | 7 ++++--- etemplate/js/et2_widget_selectbox.js | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget_menupopup.inc.php b/etemplate/inc/class.etemplate_widget_menupopup.inc.php index b5873d7453..8edd0d28d5 100644 --- a/etemplate/inc/class.etemplate_widget_menupopup.inc.php +++ b/etemplate/inc/class.etemplate_widget_menupopup.inc.php @@ -830,11 +830,12 @@ class etemplate_widget_menupopup extends etemplate_widget * * @param string $type * @param Array|String $attributes - * + * @param string $value Optional current value, to make sure it's included */ - public static function ajax_get_options($type, $attributes) + public static function ajax_get_options($type, $attributes, $value = null) { - $options = self::typeOptions($type, $attributes); + $no_lang = false; + $options = self::typeOptions($type, $attributes,$no_lang,false,$value); self::fix_encoded_options($options,true); $response = egw_json_response::get(); $response->data($options); diff --git a/etemplate/js/et2_widget_selectbox.js b/etemplate/js/et2_widget_selectbox.js index e437d9aef0..72c432a870 100644 --- a/etemplate/js/et2_widget_selectbox.js +++ b/etemplate/js/et2_widget_selectbox.js @@ -1091,7 +1091,7 @@ jQuery.extend(et2_selectbox, // and we can't do that when it's queued. egw.window.et2_selectbox.type_cache[cache_id] = egw.json( widget.getInstanceManager().app+'.etemplate_widget_menupopup.ajax_get_options.etemplate', - [widget._type,options_string] + [widget._type,options_string,attrs.value] ).sendRequest(); } cache = egw.window.et2_selectbox.type_cache[cache_id]; @@ -1116,6 +1116,24 @@ jQuery.extend(et2_selectbox, } else { + // Check that the value is in there + if(attrs.value) + { + var missing_option = true; + for(var i = 0; i < cache.length && missing_option; i++) + { + if(cache[i].value == attrs.value) + { + missing_option = false; + } + } + // Try again - ask the server with the current value this time + if(missing_option) + { + delete egw.window.et2_selectbox.type_cache[cache_id]; + return this.cached_server_side_options(widget, options_string, attrs); + } + } return cache; } }