adding optional submit_value parameter to widget getValue() method to let widgets know value is needed for submit/getValues

This commit is contained in:
ralf 2024-02-06 09:21:05 +02:00
parent 7ad9e2cd4f
commit d504d63345
4 changed files with 27 additions and 20 deletions

View File

@ -33,7 +33,7 @@ export declare class Et2InputWidgetInterface
public get_value() : any; public get_value() : any;
public getValue() : any; public getValue(submit_value? : boolean) : any;
public set_readonly(boolean) : void; public set_readonly(boolean) : void;
@ -358,18 +358,29 @@ const Et2InputWidgetMixin = <T extends Constructor<LitElement>>(superclass : T)
this.requestUpdate("readonly"); this.requestUpdate("readonly");
} }
public get readonly() { return this.__readonly}; public get readonly()
{
return this.__readonly;
}
set readOnly(new_value) {this.readonly = new_value;} set readOnly(new_value)
{
this.readonly = new_value;
}
/** /**
* Lion mapping * Lion mapping
* @deprecated * @deprecated
*/ */
get readOnly() get readOnly()
{ return this.readonly}; {
return this.readonly;
}
getValue() /**
* @param boolean submit_value true: call by etemplate2.(getValues|submit|postSubmit)()
*/
getValue(submit_value? : boolean)
{ {
return this.readonly || this.disabled ? null : ( return this.readonly || this.disabled ? null : (
// Give a clone of objects or receiver might use the reference // Give a clone of objects or receiver might use the reference

View File

@ -312,7 +312,10 @@ export class et2_inputWidget extends et2_valueWidget implements et2_IInput, et2_
return this.getValue(); return this.getValue();
} }
getValue() /**
* @param boolean submit_value true: call by etemplate2.(getValues|submit|postSubmit)()
*/
getValue(submit_value? : boolean)
{ {
var node = this.getInputNode(); var node = this.getInputNode();
if (node) if (node)

View File

@ -541,13 +541,15 @@ export class et2_htmlarea extends et2_editableWidget implements et2_IResizeable
this.value = _value; this.value = _value;
} }
getValue() /**
* @param boolean submit_value true: call by etemplate2.(getValues|submit|postSubmit)()
*/
getValue(submit_value? : boolean)
{ {
if (this.editor) if (this.editor)
{ {
// are we called by etemplate2.getValues() (has a closure result) // not always applying defaut font, as getValue() is called a lot, e.g. to test input is dirty
// not always setting it, as getValue() is called a lot, e.g. to test input is dirty if (this.options.applyDefaultFont && submit_value)
if (this.options.applyDefaultFont && this.getInstanceManager().get_values)
{ {
this.applyDefaultFont(); this.applyDefaultFont();
} }

View File

@ -1216,11 +1216,6 @@ export class etemplate2
} }
} }
/**
* Flag that getValues() is running
*/
get_values = false;
/** /**
* Fetches all input element values and returns them in an associative * Fetches all input element values and returns them in an associative
* array. Widgets which introduce namespacing can use the internal _target * array. Widgets which introduce namespacing can use the internal _target
@ -1231,8 +1226,6 @@ export class etemplate2
*/ */
getValues(_root : et2_widget, skip_reset_dirty : boolean) getValues(_root : et2_widget, skip_reset_dirty : boolean)
{ {
this.get_values = true;
const result = {}; const result = {};
// Iterate over the widget tree // Iterate over the widget tree
@ -1292,7 +1285,7 @@ export class etemplate2
id = typeof _target == "undefined" ? 0 : Object.keys(_target).length; id = typeof _target == "undefined" ? 0 : Object.keys(_target).length;
} }
const value = _widget.getValue(); const value = _widget.getValue(true); // true: let widget know getValue() / submit is calling it
// Check whether the entry is really undefined // Check whether the entry is really undefined
if(typeof _target[id] != "undefined" && (typeof _target[id] != 'object' || typeof value != 'object')) if(typeof _target[id] != "undefined" && (typeof _target[id] != 'object' || typeof value != 'object'))
@ -1335,8 +1328,6 @@ export class etemplate2
}, this, et2_IInput); }, this, et2_IInput);
this.get_values = false;
egw().debug("info", "Value", result); egw().debug("info", "Value", result);
return result; return result;
} }