board logo
WUICTeam
  • WUICTeam
  • 100% (Exalted)
  • Newbie Topic Starter
10 days ago
Question
I have a date column data_inizio with a mc_selection_changed_custom_function that computes data_fine from the new value (fourth argument), as shown in the lookup/field widget docs:

(record, field, metaInfo, newValue) =>
  record.data_fine.next(addDays(new Date(newValue), 30))
Every time I open an existing record in edit mode, data_fine is overwritten with an invalid date, even when data_inizio is empty. Logging newValue shows a BehaviorSubject object instead of the date. The same happens with multi-line text (textarea) columns. Numeric and text columns work fine.

Answer
Confirmed bug, fixed in 1.8.2. When the form opened, the date and textarea editors read the record field itself (the BehaviorSubject) instead of its current value. As a result:
  • the function was called on form open even when the field was empty, because the subject is always truthy;
  • the fourth argument (newValue) was the BehaviorSubject, so new Date(newValue) gave Invalid Date;
  • on the first user edit the fifth argument (old value) was the BehaviorSubject too.

From 1.8.2 these editors behave like the numeric and text ones: on form open the function runs only if the field has a value and receives the real value, and on the first edit the old value is the initial one.

Until you upgrade, you can guard the function: const v = newValue?.value !== undefined ? newValue.value : newValue; and return early when v is empty.