Invalid Error in DMX Date Validator for HTML5 Date Input

Wappler Version : 1.9.4
Operating System : Windows 10

Expected behavior

Setting MAX attribute of input should not allow dates after that and accept dates before that.

Actual behavior

Setting MAX attribute of input does not allow dates after that to be selected, but still fails the validation because of mismatch of date format.

How to reproduce

This is my normal input with type as DATE.
The MAX date constraint is set using a DateTime variable dateToday.

<input type="date" class="inputFloat form-control" id="dob" name="dob" autocomplete="off" data-rule-date="" required="" data-msg-required="DOB is required." dmx-bind:max="dateToday.datetime.addYears(-18).formatDate(&quot;yyyy-MM-dd&quot;)">

image

The date format of my system is dd-MMM-yyyy, which is what the browsers show, by default and cannot be changed.
But this is just the format in which the value is shown. Date inputs ALWAYS return the value in yyyy-MM-dd format.

image

The DMX validator is not checking with the actual date value for some reason.
Please check.

@patrick: Any insights on this?

The validator currently doesn’t have a rule for min/max on date fields. The min/max rule only compares numbers at this moment.

So no workaround either?
I tried using normal MIN/MAX attributes, without using dmx-bind, but it still gets validated by DMX on runtime.

Any way to mark this field as ‘dont-validate’ for DMX?

Should “type” not be text for the data picker?

That is for Wappler’s built-in date picker control. We are using HTML5 date picker.

You can try by overriding the default validator rule, add following javascript after the dmxValidator.js.

dmx.rules.max.validity = function(element, param) {
  if (element.type == 'date') {
    return element.value <= param;
  }

  return +element.value <= +param;
}
1 Like

Working great. Thanks a lot. :slight_smile:
A note: Had to add this in a document.ready function. Was getting max does-not-exist error when running directly, even if put after dmxValidator.js.

Hope to see this fixed permanently in the upcoming updates. :grin:

1 Like

@patrick Found these default functions in core.js
image

Its returning param and not +param. Which one is correct?

At least one of the two or both must be converted to a number. When at least one is a number it will do a number compare, when both are string it will do a string compare.

5 < 15 (true)
5 < "15" (true)
"5" < "15" (false)

For the date field you can do a string compare of the value, while for numbers you need to convert the value first to an actual number to prevent a string compare and false result.

1 Like

This has been fixed in Wappler 4.4.2

This topic was automatically closed after 47 hours. New replies are no longer allowed.