In-Form Dropdown Menu Buttons
How to condense a Knack Menu into a categorized Dropdown Menu on each web page


The JS
The CSS
Last updated
Was this helpful?
How to condense a Knack Menu into a categorized Dropdown Menu on each web page


Last updated
Was this helpful?
Was this helpful?
/****************************************/
/**** In-Form Dropdown Menu Buttons ****/
/****************************************/
// Define dictionary of views needing dropdown menu in editable Operating Authority (OA) pages
// Format is {"view_id" : ["Dropdown Menu Label", "page-slug"],etc...}
var dropdown = {
"view_687": ["1 - Service Type", "service-type"],
"view_750": ["2 - Business Information", "business-information"],
"view_689": ["3 - Insurance", "insurance"],
"view_691": ["4 - Additional People", "additional-people"],
"view_693": ["5 - Vehicle Information", "vehicle-information"],
"view_695": ["6 - Review and Submit", "review-and-submit"]
};
var knSlug = "#application-operating-authority";
// Function that returns the dropdown menu item
function dropdownMenuItem(slug, recordId, route, linkName) {
var buttonItem = `<li class="kn-button">\
<a href="${slug}/${route}/${recordId}/">\
<span>${linkName}</span>\
</a></li>`;
return buttonItem;
}
for (let v in dropdown) {
$(document).on(`knack-view-render.${v}`, function (event, view, record) {
var recordId = view.scene.scene_id;
var currentMenu = dropdown[v][0]; // "Dropdown Menu Label"
var currentSlug = dropdown[v][1]; // "page-slug"
// Desktop dropdown menu code
var desktopDropdownMenu = `<div class="details-dropdown-menu tabs">\
<ul id="desktop-menu-list"><li class="desktop-dropdown-menu kn-dropdown-menu kn-button">\
<a><span class="nav-dropdown-link">${currentMenu}</span><span class="kn-dropdown-icon fa fa-caret-down" /></a>\
<a href="${knSlug}/${currentSlug}/${recordId}" data-kn-slug="${knSlug}"></a>\
<ul class="kn-dropdown-menu-list desktop-dropdown-menu-list" style="min-width: 152px; margin: 0;">`;
// Mobile dropdown menu code
var mobileDropdownMenu = `<div class="mobile-details-dropdown-menu">\
<ul id="mobile-menu-list"><li class="mobile-dropdown-menu">\
<ul class="kn-dropdown-menu-list mobile-dropdown-menu-list" style="min-width: 152px; margin: 0;">`;
// Adds dropdown menuu item to desktop and mobile
for (let label in dropdown) {
desktopDropdownMenu += `${dropdownMenuItem(knSlug,recordId,dropdown[label][1],dropdown[label][0])}`;
mobileDropdownMenu += `${dropdownMenuItem(knSlug,recordId,dropdown[label][1],dropdown[label][0])}`;/****************************************/
/*** Dropdown Menu Buttons Navigation ***/
/****************************************/
/* hide custom menu if on mobile */
@media (max-width: 770px) {
#desktop-menu-list {
display: none;
}
}
/* hide knack menu buttons if on desktop */
@media (min-width: 770px) {
#mobile-menu-list {
display: none;
}
}
/*list, list item, and button stylings*/
#desktop-menu-list {
border-bottom: 0 !important;
}
#desktop-menu-list li {
margin-right: 0.5em;
box-shadow: 0px 2px 4px 0px gray;
}
#desktop-menu-list .kn-button a {
color: #163f6e;
font-size: 1.1em;
border-bottom: 0;
padding-top: 3px;
}
.desktop-dropdown-menu-list .kn-button {
border-radius: 1px;
}
.desktop-dropdown-menu-list li {
border: 0;
margin-right: 0 !important;
}
.desktop-dropdown-menu-list li:hover {
background-color:#ebebeb;
}
/*Mobile list, list item, and button stylings*/
.mobile-details-dropdown-menu ul {
margin-left: .25em;
}
#mobile-menu-list {
list-style-type: none;
margin: 0;
}
#mobile-menu-list li {
margin-top:5px;
}
#mobile-menu-list ul {
list-style-type: none;
}
#mobile-menu-list .kn-button a {
padding: 5px;
text-decoration: none;
}
.mobile-dropdown-menu span {
margin-top: .25em;
color: #163f6e;
}
.mobile-dropdown-menu-list {
margin-top: 1em;
}
.mobile-dropdown-menu-list.active {
display: inherit;
}