Skip to content

Commit 2b798e3

Browse files
asig2016claude
andcommitted
PATCH CORE: customfields - leave never-set numeric fields unset, only clear reused widgets
et2_customfields_list.set_value() coerces missing (and falsy) stored values to null before pushing them into the per-field child widgets. For float/int custom fields the child is an et2-number, whose value setter runs the value through parseFloat: parseFloat(null) parses the string "null" and yields NaN, so the input displays the literal text "NaN" and the subsequent save fails the pattern validation. Per review on upstream PR EGroupware#269: don't turn "not yet set" into "set as empty" - a pristine widget is left completely untouched on null. A plain skip is not enough though: preview / CRM-style views reuse one widget instance across records via set_value(), and skipping there would leave the previous record's number displayed on a record where the field is unset. So null is skipped only while the widget shows nothing, and clears it otherwise. The switch matches "number" as well, because _setup_float/_setup_int rewrite field.type on the shared field object during row creation. Upstream PR EGroupware#269, replacing the Et2Number-side approach of PR EGroupware#268. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit 581153c)
1 parent 9761eb8 commit 2b798e3

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

api/js/etemplate/et2_extension_customfields.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,24 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
637637

638638
switch(this.options.customfields[field_name].type)
639639
{
640+
case 'float':
641+
case 'int':
642+
case 'number': // _setup_float / _setup_int rewrite field.type to "number" on row creation
643+
// et2-number renders null via parseFloat as the literal "NaN". Leave a
644+
// never-set field alone instead of turning "not yet set" into "set as
645+
// empty", but a reused widget still showing the previous entry's number
646+
// (preview / CRM-view row clicks) must be cleared
647+
if(value === null)
648+
{
649+
const widget : any = this.widgets[field_name];
650+
const current = typeof widget.getValue === "function" ? widget.getValue() : widget.value;
651+
if(current === "" || current === null || typeof current === "undefined")
652+
{
653+
continue;
654+
}
655+
value = "";
656+
}
657+
break;
640658
case 'date':
641659
// Date custom fields are always in Y-m-d, which seldom matches user's preference
642660
// which fails when sent to date widget. This is only used for nm rows, when possible

0 commit comments

Comments
 (0)