Home Advanced Request Offering

2 Date compare and validation

Marek_LefekMarek_Lefek Customer Advanced IT Monkey ✭✭✭

Hi, I was wondering does anyone has to solve the problem with validation one date from another form the form prompt.

I have form with 2 dates that describes specified period: field Date_from and Date_to.

I need to validate form that always Date_to >=Date_from.

Without fulfils this condition, users should not save the form.

Best Answer

Answers

  • Marek_LefekMarek_Lefek Customer Advanced IT Monkey ✭✭✭

    Thanks for your help, but it won't works. I have prompts as below:

    • @DateRange  / Display only / Text
    • Date1 / Required / Date
    • Date2 / Required / Date
    but nothing happened. Of course the RO Toolbox works - I test @AutoComplete with success.

  • Konstantin_Slavin-BoKonstantin_Slavin-Bo Customer Ninja IT Monkey ✭✭✭✭
    Hm, that seems strange. So @AutoComplete works, but @DateRange does not, in the same RO?

    Could you try to copy/paste this code into the browsers devtool console (F12 > Console), and see if it works? And if it gives any errors, please copy them back here.

    function parseOptions(controlName, control) {<br>&nbsp;&nbsp;&nbsp; var properties = "{}";<br>&nbsp;&nbsp;&nbsp; var regExp = /({[^}]+})/;<br>&nbsp;&nbsp;&nbsp; var matches = regExp.exec(control.text());<br>&nbsp;&nbsp;&nbsp; if (matches && matches[1])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; properties = matches[1];<br>&nbsp;&nbsp;&nbsp; console.log(controlName);<br>&nbsp;&nbsp;&nbsp; console.log(properties);<br>&nbsp;&nbsp;&nbsp; return JSON.parse(properties);<br>}<br><br>function createDateRange(tag, tagElement) {<br>&nbsp;&nbsp;&nbsp; var userDefined = parseOptions(tag, tagElement);<br>&nbsp;&nbsp;&nbsp; var startDate = tagElement.next();<br>&nbsp;&nbsp;&nbsp; var endDate = startDate.next();<br>&nbsp;&nbsp;&nbsp; tagElement.addClass("custom-item-daterange");<br>&nbsp;&nbsp;&nbsp; tagElement.html("<div class='col-md-4 col-xs-12 startdate'></div><div class='col-md-4 col-xs-12 enddate'></div>");<br>&nbsp;&nbsp;&nbsp; startDate.find("div.col-md-4").removeClass("col-md-4");<br>&nbsp;&nbsp;&nbsp; endDate.find("div.col-md-4").removeClass("col-md-4");<br>&nbsp;&nbsp;&nbsp; function startChange() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var startDate = startDatePicker.value()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , endDate = endDatePicker.value();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (startDate) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startDate = new Date(startDate);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startDate.setDate(startDate.getDate());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endDatePicker.min(startDate);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else if (endDate) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startDatePicker.max(new Date(endDate));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endDate = new Date();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startDatePicker.max(endDate);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endDatePicker.min(endDate);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; function endChange() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var endDate = endDatePicker.value()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , startDate = startDatePicker.value();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (endDate) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endDate = new Date(endDate);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endDate.setDate(endDate.getDate());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startDatePicker.max(endDate);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else if (startDate) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endDatePicker.min(new Date(startDate));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endDate = new Date();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startDatePicker.max(endDate);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endDatePicker.min(endDate);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; var startDatePicker = startDate.find('input[data-control="dateTimePicker"]').data("kendoDateTimePicker");<br>&nbsp;&nbsp;&nbsp; startDatePicker.bind("change", startChange);<br>&nbsp;&nbsp;&nbsp; var endDatePicker = endDate.find('input[data-control="dateTimePicker"]').data("kendoDateTimePicker");<br>&nbsp;&nbsp;&nbsp; endDatePicker.bind("change", endChange);<br>&nbsp;&nbsp;&nbsp; startDatePicker.max(endDatePicker.value());<br>&nbsp;&nbsp;&nbsp; endDatePicker.min(startDatePicker.value());<br>&nbsp;&nbsp;&nbsp; startDate.detach().appendTo(tagElement.find("div.startdate"));<br>&nbsp;&nbsp;&nbsp; endDate.detach().appendTo(tagElement.find("div.enddate"));<br>}<br><br>$("p:contains('@DateRange')").parent().parent().each(function() {<br>&nbsp;&nbsp;&nbsp; createDateRange("@DateRange", $(this))<br>});<br>

  • Marek_LefekMarek_Lefek Customer Advanced IT Monkey ✭✭✭
    The code works. I find the problem. The second date can't have set range in option of Config Prompt.
    I try to set the maximum range of Date2 prompt and the @DataRange don't work. When remove the range in Config Prompt it wokrs.

    I configure it according to post https://community.cireson.com/discussion/comment/10730#Comment_10730Konstantin_Slavin-Bo



  • Konstantin_Slavin-BoKonstantin_Slavin-Bo Customer Ninja IT Monkey ✭✭✭✭
    @Marek_Lefek
    Aha okay. Yeah, it seems there's something overriding the values, which are set on the custom date pickers, with the values from RO config, each time the field is in focus. I'll see if I can find a fix for this, but I can't make any promises on neither time or success.
Sign In or Register to comment.