0

I have a form where I have three input fields (one as date, one as start time and the other as end time) which are in arrays. Like this:-

<input type="text" class="form-control datetimepicker-input" data-target="#sDatePicker_1" data-toggle="datetimepicker" id="sdating_1" name="sdate[]" placeholder="Select Day"/>
<input type="text" class="form-control datetimepicker-input" data-target="#fromTimePicker_1" data-toggle="datetimepicker" id="stime_1" id="stime[]" placeholder="HH : MM"/>
<input type="text" class="form-control datetimepicker-input" data-target="#toTimePicker_1" data-toggle="datetimepicker" id="etime_1" id="etime[]" placeholder="HH : MM"/>
<input type="text" class="form-control datetimepicker-input" data-target="#sDatePicker_2" data-toggle="datetimepicker" id="sdating_2" name="sdate[]" placeholder="Select Day"/>
<input type="text" class="form-control datetimepicker-input" data-target="#fromTimePicker_2" data-toggle="datetimepicker" id="stime_2" id="stime[]" placeholder="HH : MM"/>
<input type="text" class="form-control datetimepicker-input" data-target="#toTimePicker_2" data-toggle="datetimepicker" id="etime_2" id="etime[]" placeholder="HH : MM"/>
<input type="text" class="form-control datetimepicker-input" data-target="#sDatePicker_3" data-toggle="datetimepicker" id="sdating_3" name="sdate[]" placeholder="Select Day"/>
<input type="text" class="form-control datetimepicker-input" data-target="#fromTimePicker_3" data-toggle="datetimepicker" id="stime_3" id="stime[]" placeholder="HH : MM"/>
<input type="text" class="form-control datetimepicker-input" data-target="#toTimePicker_3" data-toggle="datetimepicker" id="etime_3" id="etime[]" placeholder="HH : MM"/>

I am using jQuery validate to validate the form. I need a jQuery form validation rule with specific requirement:

  1. The date value can be same in multiple sdate[] field. This is because user can give multiple training session in one day.
  2. If sdate[] value is same for mulitple rows, then the value of stime[] and etime[] of one row must not clash/conflict or fall within the time period of any other stime[] and etime[] field have same sdate[] value.

For example, if s_date_1 and s_date_2 is both 07/10/2019 and if stime_1 and etime_1 is 08.00 AM and 9.00 AM, then stime_2 can't be 08.30 AM.

I know jQuery validation, but in this case I am clueless about how to start.

halfer
  • 19,824
  • 17
  • 99
  • 186
Saswat
  • 12,320
  • 16
  • 77
  • 156
  • You have enough reputation to know that you are supposed to supply enough code for a MCVE, but you're just showing us a list of input elements. Where is the rest of the relevant HTML markup of the form? Where is the call to the `.validate()` method? Where is your attempt at any of this? If you're *"clueless about how to start"*, then start by clicking the [tag:jquery-validate] tag and doing a search. – Sparky Jul 23 '19 at 14:23
  • Finally, one helpful tip, you cannot have multiple text elements sharing the same name, such as `sdate[]`. For this plugin (this is also in the documentation) the input elements **must** have ***unique*** names. There is no workaround for this and plenty of people have asked before. – Sparky Jul 23 '19 at 14:30
  • @Sparky, I am very well accustomed with Jquery Validate plugin and have atleast worked 100+ different cases. This scenario is unique and I have no idea about how to write the rule for this **particular trivial** case. Why should I put a generic validation rule for the `sake of posting` if it won't be even distant closer for my requirement? – Saswat Jul 24 '19 at 05:41
  • @Sparky. Jquery Validation works fine on array elements too, like `sdate[]` having same name. Please check this link:- https://stackoverflow.com/questions/24670447/how-to-validate-array-of-inputs-using-validate-plugin-jquery – Saswat Jul 24 '19 at 05:42
  • You are mistaken. The answer on that question requires that you edit the programming of the plugin itself. You should also read the documentation: https://jqueryvalidation.org/reference/#link-markup-recommendations – Sparky Jul 24 '19 at 14:26

0 Answers0