Before I start explaining our newest feature for developers, I want to take a moment and show my gratitude to all people who stick with Divhunt and believe. Rest assured that we wonât stop until we become one of greatest no-code tools with a much larger ecosystem that you can imagine behind it.
From today, itâs possible to write custom JavaScript in any field that accepts variables, what does that mean?
Perform mathematical operations.
Perform string JS functions (replace, toLowerCase, substring, and many more).
Perform array JS functions (sort, reverse, reduce, filter, and many more).
Perform validation with regex (allow/disallow specific characters, etc)
and many more
We will release also UI which for this, which will generate JavaScript code for you, as we are no-code builder, but wanted to share this feature so you can use it even now for those who want to be limitless.
Letâs dive into some examples, however keep in mind that you can implement anything thatâs already possible with JavaScript in your own way.
Simple Mathematical Operations
Addition, subtraction, multiplication, division, and many more.
This is amazing. Maybe a bit of an outside-the-box question, but can we use âthisâ objects in those fields? Right now, Iâm trying to set something up with a GET call using Divhuntâs API that takes a query parameter set through Properties. If I could use âthisâ in that field, I could target the innerText of an ancestor of âthisâ and effectively pull in different sets of data for different iterations of a loop. Is that possible yet, or am I jumping ahead? (Even if that wonât work, this is awesome news.)
And Iâm sure Iâm not the only one who feels this way, but you guys consistently make it a no-brainer to stick with Divhunt.
I should have clarified (my bad!). The API that Iâm calling (Coda) allows me to send, as part of the GET request, a parameter that theyâve named âqueryâ (totally different thing from the URL or any query params of the current page), the value of which filters what data Coda sends back to me.
Iâm making a sort of calendar that has to have each week as a separate entity (i.e. a massive grid wouldnât work). I was thinking I might try something like this:
Make a flex box for one week.
Loop it for all the others.
Change the innerText of a .weeknumber value within each one to reflect the number of the week it will hold
Reference that value in the âqueryâ variable of the API call using âthisâ
In theory, if I could use something like this.closest('.weeknumber').innerText, in the API call, the âqueryâ that I send to Coda could autoupdate based on the .weeknumber element within that loop item.
Does that make sense? If not, I can send screenshots (itâs a little ugly right now, but if it would help clarify the function, I can post some).
Ultimately, I guess Iâm trying to see if I can use this as a loophole to effectively pull content from different sources into looped items with the dynamic âthis.â
Hmm, thatâs not possible. Because we donât have access to element (target).
This is the process:
Rendering element tags
Rendering tag text + attributes + classes
Showing entire HTML to page.
So we donât have target before we show that HTML to page, but rending text happens before we show it, so itâs not possible to have access to target there.
I still donât understand fully, but what can you do, is maybe use the page query, so thereâs 2 options.
You can have link tags, and under Advanced tab, thereâs Query options, so you can add letâs say sort => something
And when someone click on that link, it will open the page with ?sort=something, then you can use $query->get(âsortâ)
Another way is to use form element, and on Content tab you have Page to set, meaning on form submit, it will load the page and all form elements put in query, so if you had input with name sort it will send user to page with ?sort=value_from_input
So thatâs 2 ways how you can build filtering or similar.