From 87d241a10f55793e1add6b16933748cc64932173 Mon Sep 17 00:00:00 2001 From: stilbruch Date: Sat, 23 Apr 2022 19:21:36 -0500 Subject: More progress on forms --- app/forms/workout.py | 18 ++++++++++-------- app/static/js/record.js | 5 +---- app/tables/workout.py | 4 ++-- app/templates/workout/create.html | 21 +++++++++------------ 4 files changed, 22 insertions(+), 26 deletions(-) (limited to 'app') diff --git a/app/forms/workout.py b/app/forms/workout.py index a84eb6a..b406024 100644 --- a/app/forms/workout.py +++ b/app/forms/workout.py @@ -1,14 +1,20 @@ from flask_wtf import FlaskForm, Form -from wtforms import FieldList, FormField, IntegerField, StringField +from wtforms import FieldList, FormField, IntegerField, SelectField, StringField from wtforms.validators import DataRequired, Email -# Subclasses +# /workout/create class ExerciseCreateForm(Form): - name = StringField("name", [DataRequired()]) + # TODO no exercise_*, breaks workout_edit endpoint + exercise_name = StringField("name", [DataRequired()]) sets = IntegerField("sets", [DataRequired()]) units = IntegerField("units", [DataRequired()]) - type = StringField("type", [DataRequired()]) # TODO: make sure its time or reps + exercise_type = SelectField("type", [DataRequired()], choices=[('reps', 'Reps'), ('time', 'Time')]) +class WorkoutCreateForm(FlaskForm): + name = StringField("name", [DataRequired()]) + exercises = FieldList(FormField(ExerciseCreateForm), min_entries=1) + +# /workout/record class SetForm(Form): lbs = IntegerField("lbs", [DataRequired()]) reps = IntegerField("reps", [DataRequired()]) @@ -17,9 +23,5 @@ class ExerciseRecordForm(Form): sets = FieldList(FormField(SetForm)) # Actual forms -class WorkoutCreateForm(FlaskForm): - name = StringField("name", [DataRequired()]) - exercises = FieldList(FormField(ExerciseCreateForm), min_entries=1) - class WorkoutRecordForm(FlaskForm): exercises = FieldList(FormField(ExerciseRecordForm)) diff --git a/app/static/js/record.js b/app/static/js/record.js index 67ad2a6..aa5a3b3 100644 --- a/app/static/js/record.js +++ b/app/static/js/record.js @@ -4,10 +4,7 @@ allInputs = Array.from(document.getElementsByClassName('input')) allInputs.forEach(e => e.addEventListener('keypress', handleEnterKey)); function handleEnterKey(event) { - - // add ids to each input programatically - - if (event.key = 'Enter') { + if (event.key === "Enter") { event.preventDefault(); //Isolate the node that we're after diff --git a/app/tables/workout.py b/app/tables/workout.py index 164f547..564caf1 100644 --- a/app/tables/workout.py +++ b/app/tables/workout.py @@ -41,8 +41,8 @@ class Workout(db.Model): # Create exercises for exercise in exercises: - type = ExerciseType.TIME if exercise['type'] == 'time'else ExerciseType.REPS; - self.exercises.append(Exercise(exercise['name'], exercise['sets'], exercise['units'], type)) + type = ExerciseType.TIME if exercise['exercise_type'] == 'time' else ExerciseType.REPS; + self.exercises.append(Exercise(exercise['exercise_name'], exercise['sets'], exercise['units'], type)) def __repr__(self): return f'' diff --git a/app/templates/workout/create.html b/app/templates/workout/create.html index 88095f7..0336e1c 100644 --- a/app/templates/workout/create.html +++ b/app/templates/workout/create.html @@ -6,10 +6,11 @@
-

- - - +

+ {{ form.name(class_='input', placeholder='Workout Name') }} + + +

@@ -21,13 +22,12 @@

- + {{ entry.exercise_name(class_='input', placeholder='Name') }}

- @@ -35,7 +35,7 @@

- + {{ entry.sets(class_='input', placeholder='Sets') }} @@ -44,16 +44,13 @@

- + {{ entry.exercise_type() }}
- + {{ entry.units(class_='input') }}

-- cgit v1.2.3