A ha… OK, then!
Exactly. And great “example”!
A ha… OK, then!
Exactly. And great “example”!
Hi @mishav,
I’m trying to workaround the issue with elements exposure inside RGs through the JS toolbox
Is there a way to make a change to the value of the JS object?
Say I have a JS to Bubble of Fruit thing with fields name and color.
I have an input inside a RG that I can access through “an input value is changed”. So when the input name changes from orange to apple I wan’t to copy apple into the value of the JS thing value so I can then use it to make a change to the thing in the DB.
Edit: I was looking at this the wrong way. What I needed was to plant the JS element inside the RG and call it from outside to make changes to the thing from the inside.
Two days wasted on this doing the most stupid and complex things…
Hopefully this pain will make me remember this the next time I try to work with RGs
However if there is a way to change the JS value it would be great to know in case some it’s needed in the future.
Hi @JonL, can you clarify how the RG is setup, what you mean by JS element, and which JS object? Maybe a screenshot of the RG cell with a label for each piece?
You’re referring to a Bubble page workflow event “an input value is changed” for a Bubble input element? The element’s value is accessible in the workflow steps, for writing to the database, or as a parameter to a javascript function in Run Javascript step. I’m unsure where else you want to send the value to.
Hi @mishav,
It’s quite a complicated setup to be honest. One of those that will break for sure if Bubble changes how RGs are supposed to work. So I better avoid going into details because for sure it’s not how you are supposed to do things
I’ll try to explain by going directly to the point.
Fruit thing -> {name, color}
JavascripttoBubble A type of thing -> Fruit
Is it possible to achieve the following directly or with workarounds?
JavascripttoBubble A name's value = Input A's value
@JonL short answer: no. Long answer: maybe, but likely not in a useful way …
Keep in mind that a thing represents a database row, and creation of a new thing, or modification of an existing thing, involves a database operation … with the possible exception of API results, which involves a server step.
There isn’t a known way of creating a new instance of a database thing, or modifying an existing thing, in javascript, but in the plugins there is access to pass in an existing thing or list of things, and using javascript you could potentially pass the a thing around to a different element.
The Toolbox element that has things as input types is List Item Expression. So you could potentially get a list item expression to send a thing to JavascriptToBubble. I haven’t tried this, as I haven’t seen a use for it.
Thanks @mishav!
I will do some tests and let you know! As you say it doesn’t seem very useful, but just because
Hi @mishav,
Is there a way to extract the index number of a given item from a List Item Expression? The data source is a search and I want to retrieve the index of a particular item (current page’s thing) and I’m having trouble working out how to look this up in an expression. My latest attempt (using indexOf) is at least not giving me an error, but it is always returning a value of -1 (which I understand means last item in the array) even when it is the first item. Do you have any suggestions?
Below are screenshots, first of my LOE and then my JSToBubble script. If necessary I can set up a sample page tomorrow.
No -1 return value means “item not found”. You’re not finding your thing.
Thanks @keith, I could have sworn I read that -1 meant last item, which did seem odd to me at the time, but I must have read/recalled that wrong. Okay, at least I know that it must be something in my search. I’m still wondering though if I can have an expression in the List Item Expression itself, to output the index of the item, without having to use the JS to Bubble element.
Would be helpful to see the code in your LIE expression, @louisadekoya…
I removed the quotes around my var a expression and now it finds something, but it always comes back with 0. I add 1 to the value returned so actually I’m always displaying 1, whether it is the first or second item.
Thanks, @keith. I will put something on a clean page tomorrow and share if I don’t figure it out.
Zero would be first item in list (JS is zero based indices.). Found. (I guess.)
@louisadekoya You’re not getting much use of the LIE element, putting a list of texts in and pulling the same list out again.
Try using Expression instead …
['
Search for Tasks’s unique id:join with "’,’"'].indexOf('
Current Page Task’s unique id')
In the join with, put in ','
Or if you want it set by a workflow action, use the same in a run javascript, with javascript to Bubble as you have.
Thanks @mishav, as it happens I was just reading another of your posts clarifying the join with single quotes around a coma. Pretty sure that is the problem with my current ‘code’. I will give your expression a go. Many thanks.
Thanks @mishav, that works. So simple when you know how.
Nice discovery guys! It works with other things as well as user. I’d better put an example up.
So useful!
I just figured this was an undocumented feature… are you saying you didn’t know it did that??
(If so… how does it do that automagically?)
Hi @mishav , just wrote an idea post Select app data types in API connector/API workflow so this feature might be implemented in API connector and workflows.
One question : As said before, I noticed this possibility recently, so is it something that was automatically enabled in the JavascripttoBubble element or did you change something in the plugin editor ? If the former, makes me think that it is something that Bubble enable recently…
Passing an existing thing to and from javascript has been possible for a while, discussed earlier in this topic, but it was clumsy.
What is new about @mattmazzega’s discovery is only needing the unique id to reference a thing when returning an “app type” value from a plugin to Bubble.