EDIT: solved, answer below.
This one is baffling me. I have a collection that has a few fields populated by a lookup:
I have some jQuery that runs to take the value from 'Amount Remaining' and set it as the max value for the 'ALLOC AMT' field:
$(document).on("lookupcomplete", function () { //set max value per acct code row and makes the field uneditable $('.totalAmt').each(function(){ var maxVal = $(this).closest('li').parent().find('.amtRemainPerAC input').val(); $(this).find('input').attr('max', maxVal).change(); $(this).css( 'pointer-events', 'none' ); });//each } });//on lookupcomplete
This part so far is working great. I couldn't traverse the DOM without going up and then back down again. If anyone has a more elegant way other than below, please share!
$(this).closest('li').parent().find('.amtRemainPerAC input').val();
Back to the chase. When the lookup returns more than one row to the Collection, things get wonky. The first row functions fine. It is the second row (and likely subsequent) that does not validate properly. You see, just setting the max value was not sufficient. I could submit the form and no errors appeared on the ALLOC AMT fields, so I had to force the validation.
So I went in to have those fields validate on change to an input field:
$('.programAccount').on('change', 'input', function(){ $(this).closest('li').parent().find('.totalAmt input').parsley().validate(); });//change
^ the class .programAccount is the parent collection field. This is the proper way since the new rows do not appear on load. Again traversing the DOM is pretty ugly here.
Here is what I am getting for the validation error:
I have been puzzled by this for about a day now, so I have done several tests on the jQuery assuming that is where the problem lies. One test was to return the value from the specific row of the collection to ensure that it is seeing each row individually. I had the values show in the console.log and it checked out. In other words, upon change of row 1 the value appeared and then on change to row 2 the correct value appeared.
I am at a loss on where to go next, so any suggestions are welcome. Thanks so much!