Array of Checkboxes in Yesod - haskell

I would like to create an array of checkboxes in a Yesod Form and get back the answer as Bools (in a list, tuple, or something like that).
This question: Dynamically-Sized List of Fields in Yesod seems to indicate that I need to create a custom field, but the explanation of how to do this in the Yesod Book: http://www.yesodweb.com/book/forms is a little sparse and I can't quite figure out how to build it from there.
Can someone provide a working example of how to put together this kind of form element?

Yesod.Form 1.3.3 added checkboxesFieldList, which provides this functionality.

Related

Do you have a custom active admin index page builder?

I would like to build a custom index page for ActiveAdmin.
I don't mean the records shown in the index or the list of columns to display -- I mean a custom view as described here:
https://github.com/activeadmin/activeadmin/blob/master/docs/3-index-pages/custom-index.md
A Google and SO search does not turn up any code samples. I have looked at the Active Admin code itself -- but also wanted to see some examples.
Ideally, I would be able to reuse the filter and scope and table components that the index provides -- I simply want to move things around quite a bit and add a custom component or two.
Anyone have any pointers or examples?
activeadmin has nice wiki page here https://github.com/activeadmin/activeadmin/wiki/Plugins
there u can find at least several implementation of custom index components
for instance
https://github.com/bys-control/activeadmin-index_as_calendar
https://github.com/zorab47/active_admin-sortable_tree
And of course take a look at sources
https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/index_as_grid.rb
https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/index_as_table.rb
https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/index_as_blog.rb
https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/index_as_block.rb
You can try to inherit from one of them and add your own missed parts, depends on your needs

How to display one lookup's values depends on another lookup's value?

I want to display a set of values in one lookup's control depends on another lookup's control in same list. so what I want to do for this situation? both look ups are pointing the same list...
its like choosing states from country list... and is there any simple way?
You can use SPServices library if you are looking to do it on client side Javascript.
It has SPCascadeDropdowns function especially for this purpose.
http://spservices.codeplex.com/wikipage?title=%24().SPServices.SPCascadeDropdowns
What you are looking to do is to create a cascaded dropdown list.
Take a look at the folling link: http://www.codeproject.com/Articles/619373/Cascading-drop-downs-with-Cross-site-Lookup-for-Sh
You will need to adapt it a little bit, but it should work fine.

Any way in Expression Engine to simulate Wordpress' shortcode functionality?

I'm relatively new to Expression Engine, and as I'm learning it I am seeing some stuff missing that WordPress has had for a while. A big one for me is shortcodes, since I will use these to allow CMS users to place more complex content in place with their other content.
I'm not seeing any real equivalent to this in EE, apart from a forthcoming plugin that's in private beta.
As an initial test I'm attempting to fake shortcodes by using delimited strings (e.g. #foo#) in the content field, then using a regex to pull those out and pass them to a function that can retrieve the content out of EE's database.
This brings me to a second question, which is that in looking at EE's API docs, there doesn't appear to be a simple means of retrieving the channel entries programmatically (thinking of something akin to WP's built-in get_posts function).
So my questions are:
a) Can this be done?
b) If so, is my method of approaching it reasonable? Or is there something stupidly obvious I'm missing in my approach?
To reiterate, my main objective here is to have some means of allowing people managing content to drop a code in place in their content that will be replaced with channel content.
Thanks for any advice or help you can give me.
Here's a simple example of the functionality you're looking for.
1) Start by installing Low Replace.
2) Create two Global Variables called gv_hello and gv_goodbye with the values "Hello" and "Goodbye" respectively.
3) Put this text into the body of an entry:
[say_hello]
Nice to see you.
[say_goodbye]
4) Put this into your template, wrapping the Low Replace tag around your body field.
{exp:low_replace
find="[say_hello]|[say_goodbye]"
replace="{gv_hello}|{gv_goodbye}"
multiple="yes"
}
{body}
{/exp:low_replace}
5) It should output this into your browser:
Hello
Nice to see you.
Goodbye
Obviously, this is a really simple example. You can put full blown HTML into your global variable. For example, we've used that to render a complex, interactive graphic that isn't editable but can be easily dropped into a page by any editor.
Unfortunately, due to parse order issues, EE tags won't work inside Global Variables. If you need EE tags in your short code output, you'll need to use Low Variables addon instead of Global Variables.
Continued from the comment:
Do you have examples of the kind of shortcodes you want to support/include? Because i have doubts if controlling the page-layout from a text-field or wysiwyg-field is the way to go.
If you want editors to be able to adjust layout or show/hide extra parts on the page, giving them access to some extra fields in the channel, is (imo) much more manageable and future-proof. For instance some selectfields, a relationship (or playa) field, or a matrix, to let them choose which parts to include/exclude on a page, or which entry from another channel to pull content from.
As said in the comment: i totally understand if you want to replace some #foo# tags with images or data from another field (see other answers: nsm-transplant, low_replace). But, giving an editor access to shortcodes and picking them out, is like writing a template-engine to generate ee-template code for the ee-template-engine.
Using some custom fields to let editors pick and choose parts to embed is, i think, much more manageable.
That being said, you could make a plugin to parse the shortcodes from a textareas content, and then program a lot, to fetch data from other modules you want to support. For channel entries you could build out of the channel data library by objectiveHTML. https://github.com/objectivehtml/Channel-Data
I hear you, I too miss shortcodes from WP -- though the reason they work so easily there is the ubiquity of the_content(). With the great flexibility of EE comes fewer blanket solutions.
I'd suggest looking at NSM Transplant. It should fit the bill for you.
There is also a plugin called Shortcode, which you can find here at
Devot-ee
A quote from the page:
Shortcode aims to allow for more dynamic use of content by authors and
editors, allowing for injection of reusable bits of content or even
whole pieces of functionality into any field in EE

Snap: Getting form data and the "if"

I dont seem to be able to understand how to get the form data with heist.
I just started looking into Haskell web frameworks but documentation is a bit ... scarce, to say the least. There is no mention of forms in the skinny heist tutorial on the snap website.
So given a simple html form, how do I get the form data for processing into my handler function? Can anyone point me to a tutorial, google just keeps quiet on this one? Or maybe a short example ...
Also, where do I get information on the conditional control? Say, if I want conditionally include certain parts of the html within my page, how do I do it with heist? Basically, where is the "if"?
Thanks
See Using digestive functors with Heist for a good tutorial on simple forms, and mightybyte's musings about heist. If you're planning on using multipart/form-data use the Snap.Util.FileUploads module.
You could use a Splice to generate content based on a condition.
A Splice returns a list of Node's,
mySplice = do
-- get environment conditions
-- condition could be passed in as a parameter
if condition
then return [] -- do nothing
else return [TextNode "some content"] -- see Text.XmlHtml
You would then bind this splice to a tag using something like:
bindSplice myTag mysplice defaultHeistState
And place <myTag/> in your template. When Heist renders the template, it will evaluate the splice when it encounters the tag and insert the value in its place.

Is there another way to fix Yesod's nicHtmlField?

I've been rewriting my (fairly simple) website using Yesod as a way to get familiar with the framework. Part of that involves serving some simple static (but formatted) content. To do that I decided to use the nicHtml field that is described in the Yesod book:
http://www.yesodweb.com/book/forms
It allows simple formatting and, as the book says, "thanks to the xss-sanitize package, all user input is validated and ensured to not have XSS attacks."
However, all is not well. Some formatting seems to work when you enter it into the field, but gets wiped out somewhere between entry and submission. In particular, the form uses css embedded in 'style' attributes to do things like center text, and it is these css based formatting elements that seem to get wiped out.
I used print statements to check that it wasn't my code which was somehow messing it up. Since it doesn't seem to be, I assume that xss-sanitize doesn't like any embedded css and removes it. Modifying Yesod.Form.Nic to remove the call to sanitizeBalance appears to fix the problem, so that would seem to be the cause.
Now, I can just leave it like that, since editing these static pages requires being a trusted user anyway (i.e. me at the moment), so I don't care too much about validating out nastiness. But it feels like what it is, a hack, so my question is - is there any other way around this? Or is there another package I don't know about that provides a non-broken HTML editor field for Yesod?
Will you file a bug on the Yesod issue tracker for this? I think we are going to have to allow basic css through the editor no matter which editor we use. In your case of a trusted user, right now you could find the NicEdit field type and create a similar type that won't get filtered at all. Perhaps we should create such a field.
We're actually looking at other possible rich text editors right now for use in the Yesod website, so most likely whatever we use there will end up with a module in yesod-form. Most recently Greg pointed out Aloha editor which on first glance looks pretty cool.

Resources