board logo
WUICTeam
  • WUICTeam
  • 100% (Exalted)
  • Newbie Topic Starter
16 days ago
Update: mc_validation_type now supports number and date as well, and the documentation lists the supported types. Fixed in WUIC Framework 1.8.2 .
The original answer below describes versions before 1.8.2.

Question
I set mc_validation_type to number (or date) on a column and now the form rejects every value I type. What am I doing wrong?

Answer
Nothing in your data: typed validation only recognises three types, email, url and creditcard (Luhn check). Any other value, number and date included, has no matching check, so the rule fails for every non-empty value and the client also raises a metadata diagnostic about the unknown type. Note that the documentation says "email/url/number/date depending on the build"; in the current code only those three are handled.

For numbers and dates use one of these instead:
  • mc_validation_pattern with an anchored regex, for example ^-?\d+([.,]\d+)?$. The string goes straight into a JavaScript RegExp, so without ^ and $ a partial match passes.
  • mc_validation_custom_callback for anything a regex cannot express (ranges, dependencies on other fields).


Custom callback example

const raw = record[field.mc_nome_colonna].value;
if (raw !== '' && raw != null && Number.isNaN(Number(raw))) {
  vr.message = 'Enter a valid number';
  return false;
}
return true;

Things to keep in mind
  • Values in record are BehaviorSubjects, so read them with .value.
  • The callback result is accepted only when it is exactly true. Returning 1, a string or nothing at all blocks the save.
  • Pattern, type and length rules are skipped when an optional field is empty; mandatory fields need mc_validation_required. The custom callback, instead, runs on empty values too.
  • Rules are built only for editable columns that have validation enabled (mc_validation_has).


Documentation: Validations