Pass current selectbox value so the server can make sure it's there

This commit is contained in:
Nathan Gray 2015-09-30 16:06:15 +00:00
parent 3e3bde8715
commit ce637ac759
2 changed files with 23 additions and 4 deletions

View File

@ -830,11 +830,12 @@ class etemplate_widget_menupopup extends etemplate_widget
* *
* @param string $type * @param string $type
* @param Array|String $attributes * @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); self::fix_encoded_options($options,true);
$response = egw_json_response::get(); $response = egw_json_response::get();
$response->data($options); $response->data($options);

View File

@ -1091,7 +1091,7 @@ jQuery.extend(et2_selectbox,
// and we can't do that when it's queued. // and we can't do that when it's queued.
egw.window.et2_selectbox.type_cache[cache_id] = egw.json( egw.window.et2_selectbox.type_cache[cache_id] = egw.json(
widget.getInstanceManager().app+'.etemplate_widget_menupopup.ajax_get_options.etemplate', widget.getInstanceManager().app+'.etemplate_widget_menupopup.ajax_get_options.etemplate',
[widget._type,options_string] [widget._type,options_string,attrs.value]
).sendRequest(); ).sendRequest();
} }
cache = egw.window.et2_selectbox.type_cache[cache_id]; cache = egw.window.et2_selectbox.type_cache[cache_id];
@ -1116,6 +1116,24 @@ jQuery.extend(et2_selectbox,
} }
else 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; return cache;
} }
} }