Last active
May 3, 2017 18:36
-
-
Save Sean-Spallen/8f0af709bbfc09cfd5471cf899a42e38 to your computer and use it in GitHub Desktop.
Snippet allows the user to store ACF data which is on the page and load it as select options.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Loads the venues into the Formidable Venue Select Field on page load | |
jQuery('document').ready(function(){ | |
for(var i = 0; i < venueHolder.children.length; i++) { | |
// Adds the child divs of '.venue-holder' to an array | |
var arr = venueHolder.children; | |
// Selects the current individual item of this array | |
var item = arr[i]; | |
// Creates the option div | |
var name = document.createElement("option"); | |
// Searches the current item for the '.venue-name' div and stores it in a variable | |
var itemName = item.querySelector('.venue-name').innerHTML; | |
// Sets the inner HTML of the option div to the venue name. | |
name.innerHTML = itemName; | |
// Adds the option to the Formidable venue dropdown. | |
formVenue.appendChild(name); | |
} | |
}) | |
// Listens for a change in the 'Venue' select field. | |
// Sets the current variables to whatever div has the same class as 'container-' the the vaue that was selected in the dropdown. | |
// Finds the date divs inside the current variable and adds them to an array. | |
selectVenue.addEventListener('change', function(){ | |
// Sets the current venue container to be the same as the selected venue | |
var currentVenue = document.querySelector(`.container[data-venue="${selectVenue.value}"]`); | |
// Searches the current venue dates, and adds them to an array | |
var currentVenueDate = currentVenue.querySelectorAll('.venue-date'); | |
// Clears the Formidable date select field | |
selectDate.innerHTML = "<option>Please Select</option>"; | |
// If there is no Venue Dates to be appended then cancel the function | |
if(!currentVenueDate) return; | |
// Loop creates the option div and adds the dates | |
// Finally the options are added to the Formidable date select field. | |
for(var i = 0; i < currentVenueDate.length; i++) { | |
var date = document.createElement("option"); | |
// console.log(i); | |
var temp = currentVenueDate[i]; | |
temp = temp.innerHTML; | |
date.innerHTML = temp; | |
console.log(date); | |
selectDate.appendChild(date); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment