Last active
July 27, 2020 07:00
-
-
Save robjstanley/2ad2573d106b5285ed38b568a49334ce to your computer and use it in GitHub Desktop.
Magento 2 Admin - JS to turn an array into dropdown attribute 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
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