Dynamically changed dropdowns are not refreshing. - FogBugz Knowledge Exchange most recent 30 from http://fogbugz.stackexchange.com2013-05-19T14:19:55Zhttp://fogbugz.stackexchange.com/feeds/question/10683http://www.creativecommons.org/licenses/by-nc/2.5/rdfhttp://fogbugz.stackexchange.com/questions/10683/dynamically-changed-dropdowns-are-not-refreshingDynamically changed dropdowns are not refreshing. aStokes2012-08-08T11:57:20Z2012-08-09T21:34:42Z
<p>The script below does what I want it to do except you need to change the ixproject field (Probably because my other projects do not uses subcategory) for the dropdowns to be updated with the new values. Is there a way to refresh certain html elements after their values have been changed. </p>
<pre><code>$(document).ready(function(){
var categoryChanged = $('#ixCategory');
var reloadProject = $('#ixProject');
// We don't need Schedule Item so remove it. From our options.
var removeScheduleItem = document.getElementById("ixCategory");
var select = document.getElementById("subcategorya85");
//Remove all options that may exist.
function resetSelectBox(){
var select = document.getElementById("subcategorya85");
select.options.length = 0;
}
//Remove all options before starting.
$(document).ready(function() {
resetSelectBox();
select.options[0] = new Option("--");
//removes schedule item from ixcategory
removeScheduleItem.remove(3);
});
categoryChanged.on("change", function(event){
if (($('#ixCategory')[0].selectedIndex == 0))
{
resetSelectBox();
select.options[0] = new Option("A", "A");
select.options[1] = new Option("B", "B");
select.options[2] = new Option("C", "C");
}
else
if (($('#ixCategory')[0].selectedIndex == 1))
{
resetSelectBox();
select.options[0] = new Option("D", "D");
select.options[1] = new Option("E", "E");
}else
if (($('#ixCategory')[0].selectedIndex == 2))
{
resetSelectBox();
select.options[0] = new Option("F", "F");
}else
if (($('#ixCategory')[0].selectedIndex == 3))
{
resetSelectBox();
select.options[0] = new Option("G", "G");
}
})
});
</code></pre>
<p>EDIT: I copied the exact same script to a Fiddle and got the desired result. <a href="http://jsfiddle.net/themaniac27/VNfFH/" rel="nofollow">http://jsfiddle.net/themaniac27/VNfFH/</a> </p>
<p>What do I need to do differently to get this to work in Fogbugz. This was attempted using the fogbugz on demand trial. </p>
http://fogbugz.stackexchange.com/questions/10683/dynamically-changed-dropdowns-are-not-refreshing/10695#10695Answer by db for Dynamically changed dropdowns are not refreshing. db2012-08-09T21:34:42Z2012-08-09T21:34:42Z<p>FogBugz' droplists have a variety of additional functionality added to them, so they can be a little tricky to modify directly. Basically, you need to call <code>DropListControl.refresh()</code> and pass in the underlying <code><select></code> DOM element. Another thing to consider is that FogBugz can ajaxily transition from viewing a case to editing a case.</p>
<p>Below is a <a href="http://fogbugz.stackexchange.com/questions/5520" rel="nofollow">BugMonkey</a> script that should achieve what you're after, but also handles a) how FogBugz droplists work and b) ajax page transitions.</p>
<pre><code>name: Dynamic subcategory droplist
description: Updates the available subcategory options based on the category
author: Dane Bertram
version: 1.0.0.0
js:
// if we're not on the case page, don't do anything
if (!$('#bugviewContainer').length) return;
var subcategoryId = 'subcategorya85';
var jCategory;
var jSubcategory;
var BUG = 1;
var FEATURE = 2;
var INQUIRY = 3;
var SCHEDULE_ITEM = 4;
function addOption(newVal) {
jSubcategory.append($("<option>").attr('value', newVal).text(newVal));
}
function removeScheduleItem () {
DropListControl.refresh(
jCategory
.find('option[value="' + SCHEDULE_ITEM + '"]')
.remove()
.end()[0] // pop back up to the select element
);
}
function updateSubcategory() {
var ixCategory = parseInt(jCategory.val(), 10);
jSubcategory.empty();
switch (ixCategory) {
case BUG:
addOption('A');
addOption('B');
addOption('C');
break;
case FEATURE:
addOption('D');
addOption('E');
break;
case INQUIRY:
addOption('F');
break;
default:
addOption('--');
break;
}
DropListControl.refresh(jSubcategory[0]);
}
function init() {
jCategory = $('#ixCategory');
jSubcategory = $('#' + subcategoryId);
// if the category droplist isn't present, there's nothing to do
if (!jCategory.length) return;
// we don't need Schedule Item so remove it from our options.
removeScheduleItem();
// remove all options before starting
updateSubcategory();
}
init(); // in case we just loaded the edit page
$('body').on("change", "#ixCategory", updateSubcategory);
$(window).on('BugViewChange', function(e, data) {
if (data.sCommand === 'edit') {
// add delay to allow for view transition
setTimeout(init, 100);
}
});
</code></pre>
<p>Just a couple notes:</p>
<ol>
<li>Make sure <code>subcategoryId</code> matches the <code>id</code> attribute of your subcategory's <code><select></code> element.</li>
<li>Make sure whatever options you're adding to the subcategory droplist are actually configured to exist in the Custom Fields plugin. For example, if you specify an option of "foo" when only "bar" and "baz" are configured in custom fields for the subcategory droplist, the value of "foo" will be ignored when you submit the page.</li>
</ol>