Validate range of dates with Regula - regula

Is there any way to use #Range to validate a range of dates in Regula? (ditto #Min and #Max)
Or do I need to use #Custom?
#Range(min=
and
#Range(max=
do not seem to accept anything of the type Date - only numbers or strings.

Unfortunately #Range only accepts numbers. I think you can do something like this though:
<input type="hidden"
name="date"
id="date"
data-constraints="
#Future(date='2000/1/1', format='YMD')
#Past(date='2010/1/1', format='YMD')"
/>
This ensures that the date is after 2000/1/1 and before 2010/1/1 (i.e., in between). I didn't document the date parameter because I don't think I had implemented it when I wrote the documentation. Sorry; the documentation is a bit behind because I'm working on rolling version 1.3 of Regula out, that will have a lot more goodies. I'll be getting started on updating the documentation soon!

I found that the following hack works:
I added a second, hidden input that contains the date entered in the format of Date.getTime():
<input type="hidden" data-bind="value: myDateValue.getTime()" ... />
(I'm using Kendo MVVM, but I'm sure other MVVM libraries can handle the same approach)
Then for the constraint, on server side (ASP.NET MVC in my case) I'm generating the Unix time for the min and max:
#Range(min="<%= (dateTime1 - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds %>",
max="<%= (dateTime2 - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds %>")
EDIT
Need to use .TotalMilliseconds - and even so there's some unexplained discrepancy.

Related

Selenium IDE type="date" field won't type

Im using Seleniums IDE to format a test for our web scanning environment.
On the first page, are two input fields, one for a start and one for an end date like so;
<input class="form-control" name="start_date" id="start-date" style="height:49px" value="2018-05-30" min="2018-05-30" max="2018-06-29" type="date">
For some reason, no command will type into this field, sendkeys, type, editcontent. None of them. Is there a certain way I have to format IDE to have it affect this field?
Taking a look a this, using Selenium 3.5.8 in Chrome today, I can:
type || id=start-date || YYYY-MM-DD

How does Kendo UI MVVM allow bound fields to have a format?

I'm using Kendo ui's mvvm framework, and trying to get an input to apply a format so the number is formatted to two decimal places. Something like:
<input type="text" id="myTextbox" data-format="0.00" data-bind="value: variableInMyViewModel" />
...but it's not formatting the value. Can you use data-format on an input? If not, what is the best way to accomplish this?
I would probably not use a textbox to take in a number, I would switch to a kendo numerictextbox where you can set the format (n2), and the number of decimals.
<input data-role="numerictextbox" data-decimals="2" data-format="n2" data-bind="value: variableInMyViewModel" />
See demo at kendoui
http://demos.telerik.com/kendo-ui/numerictextbox/mvvm
See documentation at kendoui
http://docs.telerik.com/kendo-ui/api/javascript/ui/numerictextbox#configuration-format

Date Select Error in Ektron

I have a form that is using the calendar/date selection tool within Ektron, but when users select the current date (or any date, for that matter), it gives an error saying that you need to select a date in the past.
We haven't tooled around in the code for this form, but it almost sounds like a validation issue.
Here's the code, as is, from Ektron.
<p align="center" style="text-align: left;">Date program was presented: 
<ektdesignns_calendar title="Date presented" id="Date_presented" onblur="design_validate_xpath('number(translate(.,\'-\',\'\')) <= number(translate($currentDate,\'-\',\'\'))',this,'Date in the past (required)');" ektdesignns_name="Date_presented" ektdesignns_caption="Date presented" ektdesignns_invalidmsg="Date in the past (required)" ektdesignns_validate="xpath:number(translate(.,'-','')) <= number(translate($currentDate,'-',''))" ektdesignns_basetype="calendar" ektdesignns_datatype="date" ektdesignns_validation="datePast-req" name="Date_presented">
<input type="text" size="30" readonly="readonly" unselectable="on" />
<img width="16" height="16" class="design_fieldbutton" alt="Select date" src="[skinpath]btncalendar.gif" unselectable="on" /></ektdesignns_calendar></p>
My knowledge on validation is limited, but it looks like it's parsing the date as an integer. Is it possible to add a day (+1) to the current date so that it interprets any day as valid as long as it's not in the future?
I guess this is a HTML form as opposed to a Smart form?
If so, have you checked the validation settings on the calendar field? If you edit the form, right-click on the field and choose Field Properties you will get the properties window. Go to the Validation tab and check the setting in the Validation drop down.
There are options for ensuring the date is in the past or the future. Perhaps one of these options has been set?

Chrome/HTML5: Input type number not respecting max attribute?

I have the following markup:
<input type="number" max="99" />
In Google Chrome (and possibly other webkit browsers), this will restrict the spinner's up arrow from going over 99, but it does not prevent the user from typing a number higher than 99. Even onblur, the invalid value is not removed/replaced or even a warning given that the value is invalid.
Am I misinterpreting how it's supposed to work, or is this a bug? I am using the latest version of Chrome (19 at the time of writing).
Edit:
To clarify, I want to know why a number greater than the specified max is allowed to be input in the first place. I realize that it gives a tooltip on form submission telling you that it's invalid, but it seems like inconsistent behavior that the spinner will not allow you to go above the max, yet you can simply type a number above the max at any time to circumvent it.
If this is desired behavior for some reason, why is that? And is there a better option to enforcing the input range without resorting to JS?
It does work but you only see an error message (tooltip) if you put a submit button and a form into your code:
<form action="#" method="get">
<input type="number" max="99" />
<input type="submit" value="Submit!" />
</form>
jsFiddle
​
It's an old question, but I didn't find any relevant answers for this question anywhere.
this behaviour is still around in chrome (version 61).
I have found a little trick that can be used in some situation.
it's relevant for those who use data-binding libraries like aurelia, angular etc.. I tested only on aurelia - but that should work also for others.
the trick relies on the fact that input of type range enforce the min/max constraints.
we simply create another input (of type range) that is bounded to the same value as the regular input, and we hide it via css.
when the user inputs something that is greater than the max value, it will snap back to the max value.
here's a demo in aurelia: https://gist.run/?id=86fc278d3837718be4691acd5625aaad

How should boolean attributes be written? [duplicate]

This question already has answers here:
What values can appear in the "selected" attribute of the "option" tag?
(8 answers)
Closed 8 years ago.
I've been reading some articles about HTML, XHTML, etc. In most of them (i.e. My preferred syntax style) say that boolean attributes should be written without any value, like this:
<input type="text" required>
They even say that it is wrong to use this attributes like this:
<input type="text" required="required">
Some of this articles link W3 which says:
If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.
but in the examples shows like this:
Here is an example of a checkbox that is checked and disabled. The
checked and disabled attributes are the boolean attributes.
<label><input type=checkbox checked name=cheese disabled>Cheese</label>
This could be equivalently written as this:
<label><input type=checkbox checked=checked name=cheese disabled=disabled> Cheese</label>
You can also mix styles; the following is still equivalent:
<label><input type='checkbox' checked name=cheese disabled="">Cheese</label>
So, how should the boolean attributes be written? Based in your experience, which of the options are cross-browser and which are not?
Attribues without values are valid in HTML, but invalid in XHTML, because it's not allowed in XML. Perhaps that's where your confusion is coming from. So, which one is valid depends on the doctype of your document.
I always use checked="checked" and disabled="disabled". I don't really have a reason for adding it, but it has always worked in all browsers that I test in. This includes IE6+.