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

This commit is contained in:
Nathan Gray 2015-09-29 16:00:12 +00:00
parent f1837813a4
commit dde1a5e51d
2 changed files with 23 additions and 4 deletions

View File

@ -831,11 +831,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);

View File

@ -1103,7 +1103,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(true);
}
cache = egw.window.et2_selectbox.type_cache[cache_id];
@ -1128,6 +1128,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;
}
}