jaspervdj / digestive-functors

A general way to consume input using applicative functors
149 stars 71 forks source link

Dynamic listings start from -1 #148

Closed CristhianMotoche closed 7 years ago

CristhianMotoche commented 7 years ago

I'd like to know why the dynamic listings start from -1. I'm pretty sure there must be a reason for this line: https://github.com/jaspervdj/digestive-functors/blob/master/digestive-functors-heist/src/Text/Digestive/Heist.hs#L476

Currently, using dynamic listings will produce an extra row that will start wil index (-1).

cimmanon commented 7 years ago

That line is exactly what it indicates: it's a template. It's intended to be a "clean" row for JavaScript to clone from when you click on the 'add another item' type button. Note that the listItemTemplate element is supposed to be hidden from the user via CSS (if you use the itemAttrs attribute splice, it adds style="display: none" to just the template element).

The index value of -1 has no real meaning, it just has to be an integer. All that matters is that if you want to add a new item to the dynamic list, its index has to included in the associated 'indices' field (by default, -1 is not listed). If you really wanted, you could write your JavaScript to decrement new index values from 0 or follow the Fibonacci sequence (excluding the duplicate 1 value, of course) , rather than increment.

CristhianMotoche commented 7 years ago

I only wanted to create a list not exactly a dynamic list. In my brief research I found this dynamic lists. However, they didn't satisfy what I wanted. So, I research a little bit more and create my own splices to solve my problem. Everything is fine now. Thanks for the explanation.

cimmanon commented 7 years ago

If you're creating your own splices, be aware that they won't be propagated via the dfSubView or dfInputList splices that come with digestive-functors because they're hard coded to only make digestive-functor's digestiveSplices splices available to its descendants. I've had to make quite a few custom splices for digestive-functors within my own projects.

https://github.com/cimmanon/digestive-functors-heist-extras/blob/master/src/Text/Digestive/Heist/Extras/List.hs