Please help with repeatable fields in my first Yii app

Hi guys,

I’m currently creating my first Yii app, and I’m really enjoying it so far. The app will be used to allow users to log their weightlifting workouts and to monitor their strength over time. Part of the app is to allow users to create their own workout routines, so for example a final workout routine might consist of:

[size="6"]Legs Routine A[/size]

Squat

Set 1

Target reps: 12

Set 2

Target reps: 10

Set 3

Target reps: 8

Deadlift

Set 1

Target reps: 10

Set 2

Target reps: 8

Set 3

Target reps: 6

Seated Calf Raises

Set 1

Target reps: 15

Set 2

Target reps: 12

I know how to display and use these workout routines, but I can’t seem to figure out how I can go about building the feature to create them. Ideally I’d like a ‘create’ page where both the exercises and their sets become repeatable fields, so you can define a certain amount of each. I have attached my database schema (the routine tables are the main ones concerned) and a wireframe design for my desired create routine page to help give you guys an idea on what I’m trying to do. I would really appreciate it if someone could point me in the right direction with this.

Many thanks,

Aaron

I think you would want some kind of input cloning for your ‘add set’ button. Look at the multimodelform or jqrelcopy extensions for some ideas.

There is also a wiki about collecting data for several models off one form that may be useful to you.

Hi, I have had a look at both multimodelform or jqrelcopy and have found them both to be quite tricky to use, I am also generating my forms with the (twitter) bootstrap extension. Any links to certain wiki articles would be appreciated.

Thanks

Wiki: How to use a single form to collect data for two or more models?

http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/

That is a complex form, good luck.

Oh and this article from Larry could also be helpful.

Handling Related Models in Yii Forms