You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
effect(()=>evaluate(result=>{// If nested object key is undefined, set the default value to empty string.if(result===undefined&&typeofexpression==='string'&&expression.match(/\./)){result=''}}))
It basically just check if the x-bind expression contains any dots, and if the expression also evaluates to undefined, then the result will be set to be an empty string.
So I'm wondering if this is the intended behavior or is this just a bug. 🤔
And this can be simply bypassed by using bracket call syntax like foo['bar']()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I've encountered this problem when I use a dot field access expression inside
x-bind
directiveEvent if the
foo.bar()
evaluates toundefined
, the attributedata-foobar
will still be set on the element.Here is a reproduction of this: Stackblitz.
And after I've looked into the code, I found this in https://github.com/alpinejs/alpine/blob/main/packages/alpinejs/src/directives/x-bind.js#L31
It basically just check if the x-bind expression contains any dots, and if the expression also evaluates to
undefined
, then the result will be set to be an empty string.So I'm wondering if this is the intended behavior or is this just a bug. 🤔
And this can be simply bypassed by using bracket call syntax like
foo['bar']()
Beta Was this translation helpful? Give feedback.
All reactions