addedValues Plugin

...Powerful Free! Database Expansion for Manila
logoBottle:

(1 or more words)


Get tropes here!
Click to see internals
Report bug


Hawaiian Hardwoods Direct

sitepic_hhd_screenshot.jpg:
Viewable with Any Browser

Members
Join Now
Login

Managing Rows in RowplaceHolder

You use a row placeholder variable when you want construct a table of information, know how many columns there will be, but don't know how many rows you will have. You could store such data into as many ordinary multiple value variables as you have columns, but its hard to keep the rows in synch, and if you don't the values of 1 column may be detached from the other columns. With a row place holder, addedValues guarantees that the the integrity of each row, no matter how many there are, is maintained.

Lets say you have a need to store the speakers in a message describing a conference. You want to keep their name, title and an optional picture shortcut. I've made a small demo of this example, in this website, which is visible to you here . I first created a new group called RPHdemo; then a multiple valued row place holder variable called RPHdemoSpeakers in that group. Now I can add 3 column variables for that row RPHdemoName, RPHdemoTitle and RPHdemoPicture, giving them appropriate properties and allowing members to edit them (crucial for the demonstration). The demonstration is to provide a way to create, edit and delete these rows on this page. For that we need a row update form and a report.

The form will be used to add new and edit existing rows. It's a row update form, we will call it RPHdemo (click to view). Row update forms are called up by the customInputForm macro but the call must specify which row to edit. Adding a new row is done by editing row with index "next". we also need a way to delete rows. These three functions can be combined into one handy packet by creating a report, which is the next step.

The first function of the report is to show all existing rows. This is just a table. But we need a way to display as many rows as exist, a number we don't know in advance, and we need a way to loop over all values. In addedValues this is done with row placeholder variables using the forEach qualifier, in our case [[RPHdemoSpeakers forEach]]. Every foreach qualfier must have a matching endForEach [[RPHdemoSpeakers endForEach]]. Any text between the forEcah and the EndForeach is inserted into the page as many times as there are rows in RPHdemoSpeakers, and column variables of RPHdemoSpeakers are implicitly indexed to get the values of the current row. Its useful to know the row Index, the number corresponding to the row, that's available with [[RPHdemoSpeakers foreachCount]]. Putting this all together, in report RPHdemo1, we have

Title Name Picture
Sir David Bayly rphdemo_DABApril01small.gif

Let's add a way to create an entry at the bottom of the table, see report RPHdemo2, which looks as follows (the add link is functional for members of this site, and you can sign up to become a member). We call the custominputFormLink macro, editing the current message with an update (row update) form RPHdemo and row Index next. That gets us to

Title Name Picture Act
Sir David Bayly rphdemo_DABApril01small.gif  
New Speaker Add

Now we need to edit existing entries. We use the same form; but pass the appropriate value to rowindex for each row, using a macro compatible way to obtain the foreach counter written forEachCount(RPHdemoSpeakers). See report RPHdemo3. This gives us

Title Name Picture Act
Sir David Bayly rphdemo_DABApril01small.gif Edit
New Speaker Add

To delete a row, we have to tell addedValues which message and row to operate on, and we need a form. We use the fact that we can build forms in addedValues reports! Report RPHdemo4 has 3 distinct differences. First the table is now surrounded by a form and end form tag. The form uses the GET method, which means teh recieint receives the data in the searchargs. We need to specify which message to operate on, that's what the <input type='hidden'name='entity' value='[[msgnum]]'> does. The action parameter contains check data to ensure that we are operating on a message that hasn't been changed by some other user. We get addedValues to compute that when it builds the report with [[RPHdemoSpeakers deleteplaceholderrowactionurl]]. Now we need a checkbox for each row, we use <input type='checkbox' name='rowIndex' value='[[RPHdemoSpeakers foreachCount]]'> notice it passes the magic rowIndex number. The last piece is to add a button at the bottom of the table, <input type='submit' value='Delete Checked'> we don't want this if there are no values to delete, so we use an addedValues conditional statement to generate nothing when there are no values. That gives us the following form

  Title Name Picture
Sir David Bayly rphdemo_DABApril01small.gif

Now we can put it all together in the final report. For this one, the picture shortcut has been expanded and the add and edit links and the delete button all appear in one report, as promised above. One stop shop to edit a spreadsheet table of values in your messages! . You'll only see this properly if you are a member of this website. I also added a link back to this page on the form, a fancier solution is often needed. One way is to have an inline frame and direct the form to that using the whatTarget parameter of customInputFormLink. Another is to have popup windows for the forms.

  Title Name Picture Act
Sir David Bayly rphdemo_DABApril01small.gif: Edit
New Speaker Add