asked on August 26, 2015
I am looking to accomplish the same result found Here but the main difference is that my use case is within a COLLECTION and for whatever reason, that is acting different than a table. Below is the code I am using for a drop-down list with job as the CSS class.
The issue I am running into, is that when the form is submitted, the values are not passed to my template field, then when the saved PDF is viewed, the Field is not shown either.
Code:
// Start Disable Duplicate Jobs Selected $(document).ready(function() { var masterList = []; var selectedList = []; //this function taken from http://stackoverflow.com/questions/7837456/comparing-two-arrays-in-javascript Array.prototype.equals = function (array) { // if the other array is a falsy value, return if (!array) return false; // compare lengths - can save a lot of time if (this.length != array.length) return false; for (var i = 0, l=this.length; i < l; i++) { // Check if we have nested arrays if (this[i] instanceof Array && array[i] instanceof Array) { // recurse into the nested arrays if (!this[i].equals(array[i])) return false; } else if (this[i] != array[i]) { // Warning - two different object instances will never be equal: {x:20} != {x:20} return false; } } return true; } function createMasterList() { masterList = []; $('#Field5\\(1\\)').children('option').each(function() { masterList.push($(this).val()); }); masterList.shift(); //remove blank value } createMasterList(); //used to check if all dropdown values have been selected function updateSelectedList() { selectedList = []; var selectedValue; $('.job').each(function() { selectedValue = $(this).find('option:selected').text(); if (selectedValue != "" && $.inArray(selectedValue, selectedList) == "-1") { selectedList.push(selectedValue); } }); } //disable the dropdown items that have already been selected function disableAlreadySelected() { $('option').each(function() { if ($.inArray(this.value, selectedList) != "-1") { $(this).attr("disabled", true); } else { $(this).attr("disabled", false); } }); } //If all values have been selected, don't let the user add more rows function hideAddButtonIfDone() { masterList.sort(); selectedList.sort(); if (masterList.equals(selectedList)) { console.log("lists equal, hiding add button"); $('#q3 .cf-collection-append').hide(); } else { console.log("lists not equal, showing add button"); $('#q3 .cf-collection-append').show(); } } $('#q3').on('change', '.job', function() { var hiddenField = $(this).siblings('.hiddenjob').find('input'); hiddenField.val($(this).find('option:selected').text()); setTimeout(function() { updateSelectedList(); disableAlreadySelected(); hideAddButtonIfDone(); }, 10); }); //when a new table row is added, disable the dropdown options that have already been selected $('#q3 .cf-collection-append').on('click', disableAlreadySelected); //when a table row is removed, update all dropdowns (the removed row's dropdown option will be re-enabled //in remaining dropdowns $('#q3').on('DOMNodeRemoved', '.kx-repeatable > tr', function() { updateSelectedList(); disableAlreadySelected(); hideAddButtonIfDone(); }); }); // End Disable duplicate jobs selected
Picture:
0
0