Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/alpinejs/src/directives.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { onAttributeRemoved, onElRemoved } from './mutation'
import { onAttributeRemoved } from './mutation'
import { evaluate, evaluateLater } from './evaluator'
import { elementBoundEffect } from './reactivity'
import { nextTick } from "./nextTick";
import Alpine from './alpine'

let prefixAsString = 'x-'
Expand Down Expand Up @@ -65,6 +66,19 @@ export function directives(el, attributes, originalAttributeOverride) {
.map(toParsedDirectives(transformedAttributeMap, originalAttributeOverride))
.sort(byPriority)

if (el.tagName.toLowerCase() === 'option') {
nextTick(() => {
const modelName = el.parentNode.getAttribute('x-model');
if (modelName) {
const currentValue = evaluate(el.parentNode, modelName);
const values = Array.from(el.parentNode.options).map(opt => opt.value);

if (!values.includes(currentValue)) el.parentNode.dispatchEvent(new Event('change', {bubbles: true}))
else if (el.parentNode.value !== currentValue) el.parentNode.value = currentValue
}
});
}

return directives.map(directive => {
return getDirectiveHandler(el, directive)
})
Expand Down