diff --git a/app/views/shared/_accessible_combobox.html.erb b/app/views/shared/_accessible_combobox.html.erb index b340883..96dda5c 100644 --- a/app/views/shared/_accessible_combobox.html.erb +++ b/app/views/shared/_accessible_combobox.html.erb @@ -31,9 +31,11 @@ // Pull the id out of the json hash based on the text the user selected $(combo).keyup(function(){ - setHiddenId($(this).val()); + var selection = <%= id %>_crosswalk[$(this).val()]; + $("#<%= id.gsub("_#{attribute}", "_id") %>").val(selection === 'undefined' ? '' : selection).change(); }).focus(function(){ - setHiddenId($(this).val()); + var selection = <%= id %>_crosswalk[$(this).val()]; + $("#<%= id.gsub("_#{attribute}", "_id") %>").val(selection === 'undefined' ? '' : selection).change(); }); // Initialize the clear buttons on load @@ -56,11 +58,6 @@ $(combo).val("").focus();//.keyup(); }); }); - - function setHiddenId(val){ - var selection = <%= id %>_crosswalk[val]; - $("#<%= id.gsub("_#{attribute}", "_id") %>").val(selection === 'undefined' ? '' : selection).change(); - } <% else %> <%= _('No items available.') %> diff --git a/lib/assets/javascripts/new_plan.js b/lib/assets/javascripts/new_plan.js index 1b18bc2..8553b80 100644 --- a/lib/assets/javascripts/new_plan.js +++ b/lib/assets/javascripts/new_plan.js @@ -4,25 +4,26 @@ $("#available-templates").hide(); // retrieve the template options and toggle the submit button on page reload - handleComboboxChange(); - handleCheckboxClick("org", $("#plan_no_org").prop("checked")); - handleCheckboxClick("funder", $("#plan_no_funder").prop("checked")); - + handleComboboxChange(); + handleCheckboxClick("org", $("#plan_no_org").prop("checked")); + handleCheckboxClick("funder", $("#plan_no_funder").prop("checked")); + // When the hidden org and funder id fields change toogle the submit button $("#plan_org_id, #plan_funder_id").change(function(){ handleComboboxChange(); }); - $(".js-combobox").keyup(function(){ - var whichOne = $(this).prop('id').split('_')[1]; - $("#plan_no_" + whichOne).prop("checked", false); - }); + // Make sure the checkbox is unchecked if we're entering text + $(".js-combobox").keyup(function(){ + var whichOne = $(this).prop('id').split('_')[1]; + $("#plan_no_" + whichOne).prop("checked", false); + }); // If the user clicks the no Org/Funder checkbox disable the dropdown - // and hide clear button + // and hide clear button $("#plan_no_org, #plan_no_funder").click(function(){ - var whichOne = $(this).prop('id').split('_')[2]; - handleCheckboxClick(whichOne, this.checked); + var whichOne = $(this).prop('id').split('_')[2]; + handleCheckboxClick(whichOne, this.checked); }); }); @@ -35,32 +36,34 @@ $("#plan_org_id").val().trim().length > 0) && ($("#plan_no_funder").prop("checked") || $("#plan_funder_id").val().trim().length > 0); - - $("#available-templates").fadeOut(); - $("#plan_template_id").val(""); if(retrieve){ - $(".form-submit").prop('disabled', false); - + $(".form-submit").prop('disabled', false); + // If the templates section isn't available then submit the form to find the template options if($("#available_templates").html() == undefined){ - $("form").submit(); + if(!$("#plan_template_id").val()){ + $("form").submit(); + } } - + }else{ - $(".form-submit").prop('disabled', true); + $("#available-templates").fadeOut(); + $("#plan_template_id").val(""); + + $(".form-submit").prop('disabled', true); } } // Clear the combobox and disable it if the box was checked // ------------------------------------------------------------- function handleCheckboxClick(name, checked){ - $("#plan_" + name + "_name").prop("disabled", checked); - if(checked){ - $("#plan_" + name + "_name").val(""); - $("#plan_" + name + "_id").val("").change(); - $("#plan_" + name + "_name").siblings(".combobox-clear-button").hide(); - }else{ - $(".form-submit").prop('disabled', true); - } + $("#plan_" + name + "_name").prop("disabled", checked); + if(checked){ + $("#plan_" + name + "_name").val(""); + $("#plan_" + name + "_id").val("").change(); + $("#plan_" + name + "_name").siblings(".combobox-clear-button").hide(); + }else{ + $(".form-submit").prop('disabled', true); + } }