Skip to main content

Does anyone know how to prevent duplicate date selections in repeating table in responsive forms rows?

 

 

This functionality is not possible in Responsive Forms unfortunately.


This is a late reply but this can absolutely be done.

 

Using a custom rule with some JS you can check the values of the date controls in sibling repeating section rows, and invalidate any rows with matching dates.

Here is a simple example

 

I’ve made a form with a Repeating Section, and a Date Control:

 

(Important!) I’ve named the Date Control so that I can reference it using this name later in my code:

 

But after my controls are on the form, I create a Validation Rule for the Date Control:

The ‘Validation Message’ is: “You cannot select a date that has already been selected in another row!”

 

The following code can be copy / pasted:

(function(rowIndex, sourceContext) {
var targetControl = NWF$("#" + rowIndex);
var selectedDate = targetControl.val();

var siblingRows = sourceContext.siblings(".nf-repeater-row:not" + "(.nf-repeater-row-hidden)");
var siblingDates = siblingRows.map(function(index, row){
return NWF$(row).find(" data-controlname='control_SomeDate'] .nf-associated-control").val();
}).get();

if (siblingDates.includes(selectedDate)) {
return true;
}

return false;
}(rowIndex, sourceContext))

 

Saving and running the form results in the following:

 

Let me know if this helps


Reply