Easy Voting System... not so easy?

I’m trying to put together an easy voting system, and for whatever reason, it’s proving not as easy as I thought.

I have a table for the vote topics: TOPICS
I have a table for the voters: USERS
I have a table to record the votes: VOTES
VOTES has three fields: (1) auto-increment number, (2) connection to TOPICS, (3) connection to USERS

I’m using a “List Component” to display the items in TOPICS. A voter can “vote” or “unvote” a topic–so it’s basically a toggle (if they’ve voted the “vote” button will turn to “unvote”. If they click that “unvote” button, their vote is removed).

Because VOTES is connected to TOPICS (instead of TOPICS to VOTES), I can’t see if the current user has voted on the topic. The only thing I can think of is using a Pipe to see if the user has already voted; if they have, display the button as “unvote”. If they click the “unvote” button, remove the record (another Pipe?). If they haven’t voted, display the button as “vote”.

Is a Pipe the only way I can do this?

I am following this one Jeremy because in principle I am trying to achieve something very similar (not voting). Almost like job applications where you can apply for a job and once you have applied, the button on the main screen shows “applied” rather than “apply”. I think it has something to do with “logged In User” field and doing a match but I am not sure how to do this.

Hey Julian,

It does sound similar. If all your records live in one table (e.g.: the applicant’s info fields and the field for having applied (i.e.: “has_applied”) you can do this with a display rule. I did something similar in another area of my app.

But if you’re like me, spread across two or more tables, I think you need to use a Pipe. Of course, I can’t even nail down that syntax right now! :sob:

1 Like

Oh no…

It appears it’s even worse than I first thought. I worked on pulling in the necessary data using a Pipe. I fought with it all day and finally got it working the way I want BUT you can’t use a Pipe value in the “Display Rule” conditional statement! Ugh.

Now I’m back to square one.

I feel like there’s got to be a way to do this but I’m at a total loss at this point.

@jeremy, @JulianMc - Using display rules based on Pipe values is actually quite tricky but has come up in the past and we’ve seen people do this using some simple JS. I’ll try and find some of that code and post it.

As far as the voting feature, it’s tricky doing all this in Action links and I’d recommend using detail pages, but that’s not as smooth.

I’ll make a video shortly on what I mean and how you can accomplish this while ensuring a user doesn’t vote twice. Essentially, instead of changing the button you add validation to restrict the vote.

Here’s a short video demonstrating the validation rule to make this work:

2 Likes

Hey Moe,

This was helpful. Thanks for sharing–and thanks for going through all the effort to come up with a solution and record it for me!

In the end, I did close to what you said. I had already set it up in a “List Component” instead of a “Table Component”. It just means you go into the details on the record’s detail page, then vote there instead of from the main List Component.

That said, it would be really nice to have a Tadabase Pipe builder tool (to form queries and whatnot, then have them translated to the REST call. And secondarily, it would be great if Pipes could be used in conditionals. Future development maybe?