Why are there extra 'volatile' options in my select, and how do I get rid of them? #964
-
https://codepen.io/jon-p-moore/pen/xxQbgjv?value=3 In the above example, the intention is to present the user with a drop-down populated from a hidden editor component (eventually, the editor component will dynamically retrieve the options, and will then be used in multiple places in the page). The selected value is initialised from a URL parameter, if present. It works OK, except that the dropdown has two extra, disabled options - one blank, and the other containing the text of the mv-default attribute ( Why have I got these additional options showing up, and what should I do to get rid of them? How come I'm seeing the code of an expression which should be evaluated (and is being evaluated, since setting the option from the URL parameter is working)? Thanks, Jon. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 4 replies
-
Hi |
Beta Was this translation helpful? Give feedback.
-
by the way, even if it's not your main question:
must be inside mv-app to be able to work |
Beta Was this translation helpful? Give feedback.
-
Hey Jon,
Unfortunately, it's a known issue (see #741) and is on our radar. I hope it'll be fixed in the next release.
For now, as a workaround, I would suggest you programmatically delete those extra options after the corresponding app is ready. The following function (or something similar) should help: (async () => {
await Mavo.inited;
await Mavo.all["APP_NAME"].treeBuilt;
$$(".mv-volatile").forEach(o => o.remove()); // Or $$(".mv-volatile", $("[mv-app='APP_NAME']")).forEach(o => o.remove());
})(); I made some changes to your pen here. Btw, @GalinhaLX is right—you need an extra app to make P.S. You shared an interesting case when you use an existing |
Beta Was this translation helpful? Give feedback.
-
Thanks for all the help. Adding @DmitrySharabin's workaround worked for me (locally, couldn't seem to get it working in codepen). I was surprised when the select editor worked - it doesn't feel as though I provide enough information for it to be hooked up, but it works nicely. It's pretty essential for the kind of applications I deal with at work - very common use cases would be editable tables of information with the same dropdown appearing on each row, based on dynamic data. This sort of works:
Only 'almost' because the styling is not consistent - there seem to be 2 styles, one with a conventional dropdown box with an arrow, the other which just looks like a textbox until clicking on it pops up a list of values. I get an inconsistent mix of these - sometimes the conventional dropdown in the first row of the table only, sometimes on all rows. It seems to be dependent on the actual data (so far, it seems that if the current value in the first row is the first value in the list, then only the first row is styled as a conventional dropdown, but that's not a solid conclusion - I'm not at the stage of caring about styles yet, so not digging into it, but it is a bit weird). Thanks for the hints on the mv-if. That was going to be my next question. I've tried various combinations with the mv-if attribute on the same element as the mv-app, without any joy, so I'm guessing that mv-if has to be strictly inside the app element, which I'll try next. Is there a convenient way of expressing mv-if=" is not undefined, is not null, and is not the empty string", and its inverse? (As far as I can tell from the docs, I can only use Mavo functions, not Javascript, in expressions, and there's no obvious candidate. |
Beta Was this translation helpful? Give feedback.
-
It is weird, indeed. It would be nice if you could reproduce it and share a reduced testcase with us. It might be a bug we'd like to know about to try to fix it.
Actually, you can use JS functions in expressions—even async ones. See an example at the end of the page.
Suppose you have property But I'm not sure what you mean about This pen covers different cases. Please, take a look. |
Beta Was this translation helpful? Give feedback.
-
If the docs give the impression people can't use regular functions in there, we should fix the docs.
|
Beta Was this translation helpful? Give feedback.
-
I'm a doc reader - I read through it all before starting. What I got from the expressions page was:
... and I can use it in square brackets by default, and without brackets in some Mavo-specific attributes.
... so this looks like a restricted syntax. Why
... ah, OK, so I don't get all of Javascript, just a subset. I missed
... because that section is labelled 'Advanced', and I'm not a Javascript developer - I thought that section was just clarifying the differences and what the restrictions are from using only a subset of Javascript. So fair enough, it's there, but it's in a section I'd certainly skip on first reading, and probably not come back to because it doesn't seem that important. Not being a Javascript developer (well, not for 20 years or so), I have encountered problems stemming from "undefined" != "null" != "", but I don't really know where undefined vs null crops up - hence my question above. |
Beta Was this translation helpful? Give feedback.
Hey Jon,
Unfortunately, it's a known issue (see #741) and is on our radar. I hope it'll be fixed in the next release.
For now, as a workaround, I would suggest you programmatically delete those extra options after the corresponding app is ready. The following function (or something similar) should help: