Thursday, June 19, 2014

Stacking Enabled/Disabled States

I get annoyed when working with forms that require data to be entered in steps, this is usually how the code works.

1. Write a "on changed" event handler for the field.
2. When fired Set all fields below to disabled.
3. Enable only the next field.
4. Repeat.

All I can think about here is DRY (Don't Repeat Yourself) but how can we accomplish it?

I'm thinking you build an ordered list of all the fields, then when an on change event handler fires, it finds where your field is in the list, and disables all below it. So from there you simply make ONE function call in ALL cases, and pass it your current field, it'll then follow the rules.

What do you think? How do you manage ordered data entry and how you select appropriate fields?

I'll try implementing this and when I finish I will post here what my results were (pains/gains).

This is a rough idea, (not an actual implementation, but should be very close)


No comments:

Post a Comment