From d82f65e95e64db5f159c4b902b73c3e3915992ce Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 3 Apr 2015 12:43:26 +0000 Subject: [PATCH] reverting r52412, as it breaks not validating not send values, sending empty array for nothing selected in selectbox instead of (not submitted) null value --- etemplate/inc/class.etemplate_new.inc.php | 2 +- .../class.etemplate_widget_menupopup.inc.php | 10 ++++++---- etemplate/js/et2_extension_nextmatch.js | 18 +++++++++--------- etemplate/js/et2_widget_selectbox.js | 7 ++++--- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/etemplate/inc/class.etemplate_new.inc.php b/etemplate/inc/class.etemplate_new.inc.php index c524ecb874..297c72c90d 100644 --- a/etemplate/inc/class.etemplate_new.inc.php +++ b/etemplate/inc/class.etemplate_new.inc.php @@ -520,7 +520,7 @@ class etemplate_new extends etemplate_widget_template { if (!is_array($v) || !isset($old[$k]) || // no array or a new array isset($v[0]) && !is_array($v[0]) && isset($v[count($v)-1]) || // or no associative array, eg. selecting multiple accounts - is_array($v) && count($v) == 0 && is_array($old[$k])) // Empty array replacing non-empty + is_array($v) && count($v) == 0) // Empty array replacing non-empty { $old[$k] = $v; } diff --git a/etemplate/inc/class.etemplate_widget_menupopup.inc.php b/etemplate/inc/class.etemplate_widget_menupopup.inc.php index 5584eb309b..9cc8c151c0 100644 --- a/etemplate/inc/class.etemplate_widget_menupopup.inc.php +++ b/etemplate/inc/class.etemplate_widget_menupopup.inc.php @@ -130,7 +130,7 @@ class etemplate_widget_menupopup extends etemplate_widget // typeOptions thinks # of rows is the first thing in options ($this->attrs['rows'] && strpos($this->attrs['options'], $this->attrs['rows']) !== 0 ? $this->attrs['rows'].','.$this->attrs['options'] : $this->attrs['options'])); $allowed = array_merge($allowed,array_keys($type_options)); - + if (!$this->attrs['multiple'] || !($this->attrs['options'] > 1)) $allowed[] = ''; foreach((array) $value as $val) @@ -213,9 +213,11 @@ class etemplate_widget_menupopup extends etemplate_widget } } } - - self::set_array($validated, $form_name, $value); + if (isset($value)) + { + self::set_array($validated, $form_name, $value); //error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value).', allowed='.array2string($allowed)); + } } else { @@ -478,7 +480,7 @@ class etemplate_widget_menupopup extends etemplate_widget { $field = self::expand_name($field, 0, 0,'','',self::$cont); } - + list($rows,$type,$type2,$type3,$type4,$type5) = $legacy_options; $no_lang = false; $options = array(); diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index f30eed6461..9f86a5e2a2 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -159,7 +159,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin // Directly set current col_filters from settings jQuery.extend(this.activeFilters.col_filter, this.options.settings.col_filter); - + /* Process selected custom fields here, so that the settings are correctly set before the row template is parsed @@ -1879,13 +1879,13 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin beforePrint: function() { // Add the class, if needed this.div.addClass('print'); - + // Trigger resize, so we can fit on a page this.dynheight.outerNode.css('max-width',this.div.css('max-width')); this.resize(); // Reset height to auto (after width resize) so there's no restrictions this.dynheight.innerNode.css('height', 'auto'); - + // Check for rows that aren't loaded yet, or lots of rows var range = this.controller._grid.getIndexRange(); this.old_height = this.controller._grid._scrollHeight; @@ -1972,11 +1972,11 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin $j('.egwGridView_scrollarea',this.div).css('overflow-y','hidden'); // Show it all $j('.egwGridView_scrollarea',this.div).css('height','auto'); - + // Grid needs to redraw before it can be printed, so wait window.setTimeout(jQuery.proxy(function() { dialog.destroy(); - + // Should be OK to print now defer.resolve(); },nm),ET2_GRID_INVALIDATE_TIMEOUT); @@ -1991,7 +1991,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin else { // Don't need more rows, limit to requested and finish - + // Show it all $j('.egwGridView_scrollarea',this.div).css('height','auto'); @@ -2031,7 +2031,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin * in beforePrint() */ afterPrint: function() { - + this.div.removeClass('print'); // Put scrollbar back @@ -2040,7 +2040,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput, et2_IPrin // Correct size of grid, and trigger resize to fix it this.controller._grid.setScrollHeight(this.old_height); delete this.old_height; - + // Remove CSS rule hiding extra rows if(this.print_row_selector) { @@ -2394,7 +2394,7 @@ var et2_nextmatch_header_bar = et2_DOMWidget.extend(et2_INextmatchHeader, } // Legacy: Add in 'All' option for cat_id, if not provided. - if(name == 'cat_id' && options != null && (typeof options[''] == 'undefined' || options[0].value != '')) + if(name == 'cat_id' && options != null && (typeof options[''] == 'undefined' || typeof options[0] != 'undefined' && options[0].value != '')) { widget_options.empty_label = this.egw().lang('All'); } diff --git a/etemplate/js/et2_widget_selectbox.js b/etemplate/js/et2_widget_selectbox.js index 5fe57e0614..2e20a90c57 100644 --- a/etemplate/js/et2_widget_selectbox.js +++ b/etemplate/js/et2_widget_selectbox.js @@ -725,11 +725,12 @@ var et2_selectbox = et2_inputWidget.extend( var value = []; jQuery("input:checked",this.multiOptions).each(function(){value.push(this.value);}); // we need to return null for no value instead of empty array, which gets overwritten by preserved value on server-side - this.value = value.length > 0 ? value : null; + this.value = value; } else { this.value = this._super.apply(this, arguments); + if (this.value === null) this.value = []; // do NOT return null, as it does not get transmitted to server } return this.value; }, @@ -876,7 +877,7 @@ jQuery.extend(et2_selectbox, } return content_options; }, - + /** * Some static options, no need to transfer them over and over. * We still need the same thing on the server side to validate, so they @@ -1028,7 +1029,7 @@ jQuery.extend(et2_selectbox, * options from the server once, then keep them to use if they're needed again. * We use the options string to keep the different possibilites (eg. categories * for different apps) seperate. - * + * * @param {et2_selectbox} widget Selectbox we're looking at * @param {string} options_string * @param {Object} attrs Widget attributes (not yet fully set)