Skip to content

Instantly share code, notes, and snippets.

@robjstanley
Last active July 27, 2020 07:00
Show Gist options
  • Save robjstanley/2ad2573d106b5285ed38b568a49334ce to your computer and use it in GitHub Desktop.
Save robjstanley/2ad2573d106b5285ed38b568a49334ce to your computer and use it in GitHub Desktop.
Magento 2 Admin - JS to turn an array into dropdown attribute options
var values = ["Red","Green","Blue"];
var unique = values.filter(filterunique);
jQuery.each(unique, function(index,value) {
if(!jQuery('input[value="'+value+'"]').length) {
jQuery('#add_new_option_button').click();
jQuery('#manage-options-panel table tbody tr:last-child .required-option').val(value);
}
});
function filterunique(value, index, self) {
return self.indexOf(value) === index;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment