Using droplist in a repeater, setting values and visibility for other columns in the same row


#1

I am trying to create a repeater that has 3 data fields: a dropdown list, an amount associated with the dropdown choice, and a date field that should only show for one of the choices and be hidden for the other 4 choices.

I found an old post that showed how to set up values for the droplist in Axure 8 and am not sure it is the best way to achieve what I am trying to do. the old forum link is Using a droplist (or any kind of list) in a repeater.

I tried using the example repeater and have had some success in creating my rows, however the total field is not calculating correctly, it appears to double everytime I add a row. And when i update rows, the hidden field shows.

Repeater w dropdowns_and totals page.rp (193.6 KB)

Appreciate any help you can provide.


#2

Each time a change is made to a repeater (update/add/delete/etc.) the whole repeater is recreated can triggers all of the events for each row again.

I’m kind of surprised the Axure 8 example even worked because it’s set to update the repeater with the values in the dropdowns after it adds a new row, which should have reset the inputs to their default states and lost whatever was entered. The short version is: “I would do it differently so, here it is.”
Repeater w dropdowns_and totals page.rp (237.9 KB)

I call an event outside the repeater to add the empty row after the repeater has finished updating with all of the entered values. Specifically, clicking the add button moves the total box by (0,0) which is set to add a new row if it’s “moved”.

For adding up the total, you need to set a case on the repeater’s OnItemLoad event that uses the [[Item.isLast]] condition so you’re not adding to the total each time the whole repeater refreshes.

Repeaters are very powerful but can be a bit tricky. There’s lots of posts about tips-and-tricks to get them to do all kinds of things once you understand their idiosyncrasies.


#3

Looks like @huban beat me to the punch here. I’ll check out that solution… Mine is probably very similar, and I’ll post it here just because I spent a few minutes updating your file as well, and a few more taking notes on what I did. Here’s my post:

Repeater w dropdowns_and totals page-v2.rp (228.9 KB)


As huban points out, one thing to realize when using a repeater is the default row–the arrangement of widgets you set it up in the repeater–is the initial starting point when a row is created. If a widget is visible (in the editor), like your date field widget named “enddate” then it is shown by default, for each and every row, until and unless you hide it. If a widget has text, that text will remain until you change it–and if a widget does not have text, it won’t get text until you set it.

Another important thing to realize is that each time you change a repeater–adding a new row, deleting a row, updating, sorting, filtering, pagination, etc. the repeater gets rebuilt, row by row, starting from the default setup. So, if you change the text of a widget in a repeater dynamically, then add a new row, that text value will be lost–because that row will get rebuilt. If you want to retain an updated text value (or visibility, state, selection, position, etc.) you’ll need a representative column in the repeater dataset, and update that row to store the text value in that column before you change the repeater in any way–like adding a new row.

So, it might sound a little silly and redundant, but to hide the date field by default, you need to hide it by default (in the editor.) Then, in a conditional case in the repeater’s Item Loaded event, show it only if “Acting Pay” is chosen. You have the latter, but you’ll need to refer to the dataset, not “text on widget” --because when a row is created, the text on the “Additional Wage type” is blank–as it should be. Currently, your case reads, If text on Additional Wage type equals "Acting Pay" which will never be true. So the case should be something like, If [[Item.AddWT]] equals "Acting Pay" …and of course you’ll need to update the repeater row when that choice is made in your dropdown, not simply set the text.

Are you ever using Column0 in your repeater? If not, you can remove it.

A tip when referring to repeater properties (or any properties and built-in variables and functions) is to use the Insert Variable or Function… dropdown in the Edit Text dialog. This is more reliable and easier than typing it out manually (at least until you’re very familiar with Axure’s expression syntax.) It also shows you the full range of what’s available. Things like “index”, “isFirst”, and “itemCount” are very useful.

  • I changed the case logic for Case 1 to refer to the AddWT column value.

  • I simplified the actions to change only the elements associated with this.

    • The general things done in every row ("If true") are specified in only one case, to avoid extra work–but also avoid confusion and help with debugging.

    • I changed the "Else if true" to "If true" (right-click on the case to change this.) When you create a new case by default it is an "Else if" but you often need to change this.

    • I removed the "Show enddate" from the "If true" case, otherwise it will always be shown.

  • I added a case of If [[Item.isFirst equals true to initialize the global variable GV_total to 0. this is important, and is the root cause of why your total is not calculated correctly.

  • I added a case of If [[Item.isLast equals true to update the text on the widget, "total" and moved the Set Text total to [[GV_total]] from "If true" to this new case–because you only need to do this once per repeater update, not once per row.

  • I changed the droplist items code to update the row instead of just setting the text on this row’s widgets–because that will be wiped out as soon as a new row is added.

  • I removed “Hide enddate” as this is redundant. Likewise, no need to change the “Dropdown list 1” panel state as it will close when repeater is updated.


#4

Thank you both for your elegant solutions and comments. You have solved my problem. I got caught up in the complexity of the earlier solution and how to handle drop down lists. Both of your solutions work well and you have taught me some new functions.