Join Now

Click here to join our
growing community:

JOIN LOGIN



Docs

Welcome Tour
Handbook
      Markups
      Variables
      Conditions
      Functions
      Forms
      Commands
      Concepts
Extensions
Pro Modules
Developers



Copyright © 2020
Terms of Use
Privacy Policy
BoltWire

Handbook

Csv

This command allows you to tap into one aspect of BoltWire's powerful csv handling capabilities (comma separated values). Additional capabilities are wove throughout various markups, functions and conditionals. Let's begin with a simple illustration of how this command works:

Suppose you had a form that allows user to enter a csv list of values--but there sloppy and added spaces like this:

apples , oranges,   bananas

That value can be fed into the csv command and it will be cleaned up to this:

apples,oranges,bananas

Here's what the function would look like:

[form]
Input list: [text fruits] [submit]
[command csv {=fruits} reset=fruits]
[command savedata fruits]
[form]

This script pulls in the user input and cleans it. To put the new value back into the fruits field (so it can be saved perhaps), I add the reset=fruits parameter. Now both fruits and csv have the new value.

Note: Alternately, you can directly apply csv cleaning to the input field like this:

[text fruits fmt=csv]

Or you can do the same thing with a command using the following markup

[command somelist {=fruits} output=csv]

Updating Lists

BoltWire's csv handling extends beyond cleaning a list. It can also be used to update a list. Suppose I have store my list in the example above at {:fruit} and want to add pears to my list or delete bananas. I can modify my function this way--putting the current values in position two (or parameter 'current'):

[form]
Input list: [text fruits] [submit]
[command csv {=fruits} '{:fruits}' reset=fruits]
[command savedata fruits]
[form]

Now by entering +pears or -bananas or both into the inpug field, BoltWire retrieves the current value and makes only the appropriate changes. To overwrite the list, simple do not enter the second parameter.

However, this still requires the user to supply the correct information. So here's a more involved example:

Check a box to change a fruit:
[form]
[t]
[r][c]Fruit I Like  [c]Fruit I Dislike
[r top][c][(list apples,bananas,cherries,oranges,pears,pineapples,mangoes fmt="[check likes[] '-{+p}'] {+p}" if="inlist '{+p}' '{:fruits}'")]
[c][(list apples,bananas,cherries,oranges,pears,pineapples,mangoes fmt="[check dislikes[] '+{+p}'] {+p}" if="! inlist '{+p}' '{:fruits}'")]
[t]
[submit]
[hidden fruits '{:fruits}']
[command csv {=likes} '{=fruits}' reset=fruits]
[command csv {=dislikes} '{=fruits}' reset=fruits]
[command savedata fruits]
[form]

Several things to notice. First, we use the list function to generate a row of checkboxes, putting each fruit on the correct like or dislike side. For the field names, notice the [] brackets. This means all the fields will be saved to one variable--with all the values converted to a csv list. If a like gets dropped, the value has a - before it, meaning to drop it. Dislikes that are checked get a + meaning to add it. The two csv commands apply the likes and dislikes to the list and resets the fruits hidden field (they could be combined in one line--just use {=likes},{=dislikes}). Finally the new data value is saved, and the form recreated with the fruits moved to where they should be when the page reloads.