I have this JQuery piece to prevent selection of dropdown options that are already selected in another field.
var $coll = $( 'select[name$="service"]' ).on( 'change', function () {
$coll.each(function () {
var val = this.value;
if ( val === 'original' ) return;
$coll.not( this ).children( '[value="' + val + '"]' ).prop( 'disabled', true );
});
});
The problem is that this only works when you start selection from scratch (empty form). When I have a form that has fields with pre-selected options, the function only kicks in after the second attempt.
Do you know how I can change this to check for pre-filled fields as well?
All I had to do was to
.trigger("change")
after document ready, so that the validation begins before the first selection.