Jump to content

Module: FieldtypePoll


apeisa
 Share

Recommended Posts

I just pushed a new module to Github. I really liked Soma's idea (and execution!) to learn new frontend stuff while building useful modules to PW. While Soma is learning Knockout, I actually find AngularJS more interesting. So here is my first "AngularJS-powered" module: FieldtypePoll. This is simple polling fieldtype for (not so serious) votings like:

Q: How is the weather today?

a) Fine

b) Rainy

c) I don't know, been coding all day

This should be all usable already, so if you are adventurous and want to help me debug, this is how to get started:

1. Grab the code

-> https://github.com/a...a/FieldtypePoll (actual fieldtype and inputfield)

-> https://github.com/apeisa/AngularJS (AngularJS and AngularUI for PW)

2. Install the FieldtypePoll module

3. Create new field, choose "Poll" as a new fieldtype

4. Add field to a template

5. Edit your template file, output the field: echo $page->whatEverNameYouGaveInStep3

6. Add some css:

.PollApe .percentage {
background: black;
font-size: 10px;
min-width: 5px;
border-radius: 4px;
padding: 4px 8px;
text-align: right;
color: white;
margin-bottom: 0.6em;
}
.PollApe .PollApeTotalVotes {
border-top: 1px solid #ccc;
}

post-18-0-22320900-1353442249_thumb.gif

  • Like 11
Link to comment
Share on other sites

Oh, and few things I would like to add:

  1. Voting only for logged in users and once per user
  2. Vote multiple options
  3. Create more than one poll per page (or at least archive old ones)
  4. Better "have you voted yet" -checking. Not sure which would be best way to go and not looking for anything bulletproof here
  5. Using some csrf-token to avoid super easy "hacking".
  • Like 2
Link to comment
Share on other sites

  • 5 months later...

Very nice, I also played a little with Angular lately and it's a pretty neat tool, so it's very nice to have it packaged up as a Processwire module already. I'm definitely looking into FieldtypePoll later, looks really promising.

Link to comment
Share on other sites

Fantastic apeisa, I'll give it a try, angularjs is awesome, in my opinion is more natural than backbone although finding some difficulties to make it work with jquerymobile.

I'll try to learn from your code and give you some feedback.

Link to comment
Share on other sites

  • 5 weeks later...

@apeisa: I'm trying to use this on a PW 2.3 site and everything seems to work from administration point of view, but so far all I'm getting is this error message when I try to echo $page->my_poll (my_poll being the name of the field) on frontend:

Fatal error: Call to a member function loadPageField() on a non-object in /example_com/wire/core/Page.php on line 651

Any idea what could be causing this?

I'll probably try to debug it properly later, but not being exactly familiar with fieldtypes / inputfields doesn't really help here.. :)

Edit: reinstalling FieldtypePoll and InputfieldPoll fixed the problem. There was something strange with the install process originally (autoinstall didn't work for InputfieldPoll, installing FieldtypePoll before AngularJS caused errors etc.) so this should've been pretty obvious solution. Anyway, problem solved and everything seems to work now, sorry for the confusion :)

PS. Have you considered adding this to the modules directory? Seems like a nice addition there.

Edited by teppo
  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...