Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kyawkyawsoezhu/17dc55da98557e351abe56a591da5130 to your computer and use it in GitHub Desktop.
Save kyawkyawsoezhu/17dc55da98557e351abe56a591da5130 to your computer and use it in GitHub Desktop.
Quality Club Elite 2017 Themed Dinner
$(function(){
function init(){
console.log("INIT");
var $firstname = $("div[id$='firstname']").parent('.control-group');
var $lastname = $("div[id$='lastname']").parent('.control-group');
var $businessname = $("div[id$='biz_name']").parent('.control-group');
var $email = $("div[id$='email']").parent('.control-group');
var $agentCode = $("div[id$='Agent_Code']").parent('.control-group');
var $tableRep = $("div[id$='iSGLiSC4']").parent('.control-group');
var $tableMates = $("div[id$='Table_mates']").parent('.control-group');
var firstNameValue = $firstname.find('input').val();
var lastNameValue = $lastname.find('input').val();
var businessnameValue = $businessname.find('input').val();
var emailValue = $email.find('input').val();
var agentCodeValue = $agentCode.find('input').val();
var forTableRep = businessnameValue + ' ' + agentCodeValue;
var forTableMate = businessnameValue + ' ' + agentCodeValue + '--' + emailValue;
var forTableMateShort = businessnameValue + ' ' + agentCodeValue;
$firstname.hide();
$lastname.hide();
$tableMates.find('select.select2-hidden-accessible').select2({
maximumSelectionLength: 11,
minimumResultsForSearch: Infinity
});
$tableRep.find('input').val(forTableRep);
$tableMates.find('select.select2-hidden-accessible').val([forTableMate]).trigger("change");
var youAvailable = ($tableMates.find('select').find("option[value='"+forTableMate+"']").attr("disabled") != 'disabled' );
removeRemoveButton();
disableSelfSelect();
$tableRep.hide();
$tableMates.on("change",function(){
var has = false;
var tableMateSelectedValue = $tableMates.find('select.select2-hidden-accessible').val();
console.log(tableMateSelectedValue);
console.log(forTableMate);
if(tableMateSelectedValue != null){
$.each(tableMateSelectedValue, function( index, value ) {
if(value == forTableMate){
has = true;
}
});
if(has == false && youAvailable == true){
$tableMates.find('select.select2-hidden-accessible').val([forTableMate]).trigger("change");
}
}
console.log(has);
removeRemoveButton();
});
$tableMates.on("click",function(){
disableSelfSelect();
$('.select2-container.select2-container--default.select2-container--open').find( "ul li:contains('You can only select 8 items')" ).text("Each table can only seat 8 qualifiers.");
});
function removeRemoveButton(){
console.log("REMOVE");
$tableMates.find('.select2-container').find('.select2-selection__choice').filter("[title='"+ forTableMateShort +"']").find('.select2-selection__choice__remove').remove();
}
function disableSelfSelect(){
$('ul.select2-results__options').find("li[id$='"+forTableMate+"']").removeAttr("aria-selected");
}
}
setTimeout(init,500);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment