Get IDs from List of Items by Class in HTMX - htmx

We have a number of rows in a table, and each table row has a HTML id="itemid-1234" etc.
What we would like to do, is to find a way of selecting all of those tr's which have a class of "selected" and be able to pass all those id's to our PHP/Ajax call script. Relatively trivial with a direct jQuery Ajax call, but haven't seen anything with HTMX.

I see two ways of solving this.
Solution 1: <form> with hidden inputs
You create a form around the table and insert a hidden input in each <tr>
Solution 2: event configRequest
You use the configRequest event and some JS to collect the data which you want to sent.
BTW: The htmx community is not very active here at Stackoverlfow up to now. The next time please sent the URL of your question to the htmx discord channel. This time I did this.

Related

DOM not refreshing with Selenium (IE, Chrome and VBA)

I'm using Selenium Basic to collect data from a website and store this into a database. The page I'm scraping is dynamic and loads more information as you scroll. I've been able to address most of this by using the implicit/ explicit waits, etc.
I am capturing all the IDs necessary to create the click action, which opens up another javascript popup for me to collect information there. However, even though I've been able to get these new IDs when the page loads by scrolling, when the app uses that new ID to click, I'm getting an error saying the element cannot be found. This is preventing me from opening up the javascript windows for these newly loaded rows.
When I go to collect this new data, the elements don't exist even though I was able to get the IDs for them.
When I look at the DOM in the browser and page source, all of it is there, so I don't believe it's an issue of letting the browser load.
I've tried utilizing the wait methods (implicit/explicit)...I've even put in hard 60 second waits through the routine. No matter what I do, the routine bombs out after the first 10 rows because it can't find the elements to the data it found after scrolling. I've also tried this using Chrome as well.
Unfortunately, the website needs to be private, so I can't provide the full code. The issue that's happening comes here:
driver.FindElementByXPath("//*[contains(text(),'" & DBA!ParseID & "')]").Click
The error I get is "Element not found for XPath("//*[contains(text(),'ID12345"')]
ParseID is the ID found from parsing elements within the body tag. So, I am able to collect all the IDs after loading all the data, but when it goes to click using the above code, it only works for the initial 10 rows. Everything loaded after that will not work (even though they've been loaded in the Browser for quite some time).
What I should be getting is, say 20 IDs which can create 20 clicks to javascript pop-ups to get more information. However, I am getting 20 IDs but the ability to only click on the first 10, even though I've loaded the entire page.
This issue hasn't been resolved the way I initially expected, but I've accomplished what I needed through a different and more efficient way.
First, when I researched this further by removing certain IDs in my loop, I noticed that this really didn't have much to do with data updating in the DOM or browser, but rather the ID itself not being found by a (still) unknown reason. It actually seems very arbitrary why it's bombing out. The ID matches the ID in the DOM, but when the string is being moved to the XPath, it can't find it in the DOM. I'm not sure why this would occur unless the string is breaking when being passed somehow, but I'll just let that one remain mysterious until someone smarter comes along!
What I did to accomplish what I needed is loop through the actual class N times, and pull the elements I needed within the classes. Rather than use the ID above as a unique identifier, I used the count of class web elements as the identifier. This worked with 90% less code.
Thank you all!

Tumblr like button not working after infinite scroll ajax recall

There are a few similar posts but they are quite out of date and Tumblr has updated the like part of the API not too long ago as far as I'm aware.
Creating a like button is as simple as
{LikeButton}
and this works great, but after the ajax recalls to get more posts from what would be the next page, the like button no longer works.
I have had a look at the documentation and it states that I need to implement one of the following, I was wondering if anyone could point me in the right direction? I've been trying to get this to work for hours.
I made up an example blog if this helps contribute to answering, the javascript can do the mass amount of the implementing of new images.
http://stackoverflowexample.tumblr.com/
If you need anymore info, i'll happily edit this and add what's required, thank you!
Overview
Adapted from my previous answer here: Using Tumblr Like Button with Infinite Scroll
Tumblr states we need to call one of two functions to get the Like Status. I would suggest the following:
Function: Tumblr.LikeButton.get_status_by_post_ids([n,n,n])
Description: Request Like status for individual posts. Takes an array of post IDs
Once the ajax request is successful , we should have a data object (containing new posts, etc).
We need to create an array of postIDs, which is an array containing an ID / number for each post in the data object. Easiest way to add the the post id is to use the theme variable {PostID}.
Example
HTML
<article class="post" id="{PostID}">...</article>
jQuery Post IDs Array
var $newPosts = $(data).find('.post');
var $newPostIDs = $newPosts.map(function () {
return $(this).attr('id');
}).get();
Tumblr.LikeButton
Tumblr.LikeButton.get_status_by_post_ids($newPostIDs);
Hints
Create the array and call Tumblr.LikeButton once the ajax request is successful and in a place where you run other functions for the new Posts. This can also be done with pure javascript as using: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

Using ajax for rails image preview in form

I've been working on this issue for about two days now. I've posted more task specific questions, got great answers, only to figure out the approach I was taking wouldn't work.
Basically, I want a user to be able to upload images in a form and see a preview of the image they upload before submitting the form. The images and the parent form have a has_many relationship. The images are nested in the parent form using fields_for.
I tried using a client side approach, but ran into cross browser and security issues. My current approach I'm trying is to save the images, reload the div portion of the page, and then assign the parent_id to the image after the partent form is submitted (since I will not have a id for the partent form until it is created).
Is it possible to use ajax to submit the fields_for portion of a form and not the entire parent form? Has anyone attempted to do something similar?
Of course you can submit only the fields of that image by using jQuery to select only the fields that you want to send, serialize them and send them as data of the ajax request.
Be careful, you need to send the authtoken, that's why I have type=hidden in the selector
var data = form.find('[name*=image],[type=hidden]').not('[name*=items]').serialize();
$.ajax({url: this.form.attr('action'), context: this, type: 'POST', data: data
The next step with the image I once implemented as storing the in their own database table, returning the client the id to that who then adds it to the form.

POST a HTML Form programmatically?

I need to POST a HTML form to a 3rd party website (a Mass-SMS texting system).
In the past I've done this by forwarding to a page containing a form I've pre-populated and hidden (using display:none), then I've ran a javascript function at the end of the page to automatically submit this form.
However I'm hoping theres someway I can do all this programmatically (as I don't care about the response, and the user doesn't need to see the page the form is being posted to).
How can I do this? Cheers
You could use a WebClient.UploadValues method to send an HTTP POST request to a remote server from your code behind. Just fill up the name/value collection with the values coming from the hidden fields.
If you're willing to get into PHP, you can very easily use cURL for this.
Otherwise it's going to be quite difficult using just Javascript.
See here for a detailed tutorial.

Dynamic Div placement based on number of values in a list

I want to be able to change the design of the website based on the content in my database. For example: I have a list of instances of objects that is being pulled from a database, and will be used to populate my website. I want the website to look similar to www.reddit.com, where there is a <div> for each post. However, I can't figure out how to variably change the location of that <div>. So for the first instance of that object it will be located at top:60px; the second top:200px; etc... (not those exact numbers). If you need any clari
Was looking for some help! Thanks,
Figured it out! I added a variable that I then used to define the "top:" in the html of the template. If anyone wants me to explain further please let me know.