I've encountered some usual behavior in version 11 that I'm hoping someone can help me understand why it is doing what it is doing.
I have a form with a bunch of different checkbox elements on it. Each checkbox has multiple different options under it with different values. Based on the employee's "Job Category" the checkbox options that apply to their position are shown and the others are hidden.
I'm handling this via the :nth-child selector on the choice class in Javascript. This is working well in version 10.2, but in version 11 (specifically update 2), it's behaving in an unusual manner.
Here's a simplified version of my code, which hides three checkbox options and then only shows the specific item that applies based on the value in the jobCategory field:
$(document).ready(function () { $('.crossSaleCheckbox').each(function() { $(this).find('.choice:nth-child(1)').hide(); $(this).find('.choice:nth-child(2)').hide(); $(this).find('.choice:nth-child(3)').hide(); }); if ($('.jobCategory input').val() == 'Executive') { $('.crossSaleCheckbox .choice:nth-child(1)').each(function() { $(this).show(); }); } else if ($('.jobCategory input').val() == 'Manager') { $('.crossSaleCheckbox .choice:nth-child(2)').each(function() { $(this).show(); }); } else if ($('.jobCategory input').val() == 'HR') { $('.crossSaleCheckbox .choice:nth-child(3)').each(function() { $(this).show(); }); } });
That code is working as expected in version 10.2.
However, in version 11, it seems to be off by 1. If I change all the :nth-child selectors from 1-->2, 2-->3, and 3-->4, then it works as expected. It's like it is starting the counter at 2 instead of 1...
This modified code works in version 11:
$(document).ready(function () { $('.crossSaleCheckbox').each(function() { $(this).find('.choice:nth-child(2)').hide(); $(this).find('.choice:nth-child(3)').hide(); $(this).find('.choice:nth-child(4)').hide(); }); if ($('.jobCategory input').val() == 'Executive') { $('.crossSaleCheckbox .choice:nth-child(2)').each(function() { $(this).show(); }); } else if ($('.jobCategory input').val() == 'Manager') { $('.crossSaleCheckbox .choice:nth-child(3)').each(function() { $(this).show(); }); } else if ($('.jobCategory input').val() == 'HR') { $('.crossSaleCheckbox .choice:nth-child(4)').each(function() { $(this).show(); }); } });
The thing is - I've been backwards and forwards through the browser inspect element view - and I don't see any extra elements with the choice class - just the expected ones - nothing to explain why the counter is starting at 2 instead of 1.
Since this is pretty basic Javascript/JQuery functionality, I don't see how the Forms version change would be causing this behavior either.