Last active
November 26, 2022 04:07
-
-
Save valiantboymaksud/6f341a65ee9954fa92c24a2bddc70c71 to your computer and use it in GitHub Desktop.
Auto Select which help to select option value dynamically. You can also select multiple option
This file contains hidden or 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
const { isArray } = require("lodash"); | |
$('select').each(function() { | |
let _this = $(this) | |
let selected = $(this).data('selected'); | |
if (isArray(selected)) { | |
selected.forEach(element => { | |
_this.val(element).prop('selected', 'selected') | |
}); | |
} | |
if (typeof selected === "undefined") { | |
return; | |
} | |
_this.val(selected).prop('selected', 'selected') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment