The issue you're seeing is that every time your code runs it is referencing the same "firstDate" match because your code doesn't "target" a specific row or relative object.
If you want it to work the way you describe, then it needs to have a more dynamic way of finding the "associated" field(s) rather than just the first match.
To do this, you could either extract the index of the "current" field that triggered the change, or use parent functions to find the "relative" field, the latter being the preferable approach.
Second, the way you have the code written, it looks like it is going to reassign those handlers every time the table changes, which I don't think is at all desirable. Ideally, you should only need to assign the handlers once when the form first loads (document ready event).
For example,
$(document).ready(function(){
// detect any change to the table, filtered by the firstDate field
$('.myTable table').on('change','.firstDate input',function(){
// get the start date
var minDate = $(this).val();
// set the min end date on the "secondDate" field within the same row as the one that changed
$(this).parents('tr').find('.secondDate input').attr('min',minDate);
});
});
DISCLAIMER: This code will only work if you keep the date format as you have it (yyyy-MM-dd). If you want to use a different format, you would need to extract the value and convert it to yyyy-MM-dd before you assign it to the minDate attribute otherwise it will cause errors.
Fortunately, Forms imports the moment.js library, which makes it easier to format date objects.
For example, if you wanted to display 01/31/2020 to the user instead of 2020-01-30, you could use moment.js to convert that date into a valid format by changing line 5
// get the start date and format it for min date attribute
var minDate = moment($(this).val(),'MM/DD/YYYY').format('YYYY-MM-DD');
First you have moment($(this).val(),'MM/DD/YYYY')
Which is getting the value of the trigger field and saying it is in 01/31/2020 format.
Next, .format('YYYY-MM-DD') is converting 01/31/2020 to 2020-01-31, which is what the min date attribute requires.
All you need to do is match the "input" format to whatever you display on the field and you won't the user view to match exactly what is expected by the attribute.
https://momentjs.com/docs/#/displaying/