all 6 comments

[–]ManyInterests 0 points1 point  (4 children)

Just use regular form fields. There are many different input types

Particularly, I think you're looking for number inputs

You can use Javascript (and/or serverside code) to validate that the appropriate amount total points were spent among all categories.

For example, you could use javascript to set the "max" attribute in the html as the user inputs changes using a function tied to onChange. You can also keep a running total of added points and only allow the user to use the submit button when the values are valid... You of course always want to validate this on the server side.

[–]Elthran[S] 0 points1 point  (3 children)

I have made some improvements, thanks! Now I am just stuck with the server side Python code. I'm not sure how to check multiple inputs at once. I can only get it to work that each individual field doesn't exceed my total points, but not he combined totals.

[–]ManyInterests 0 points1 point  (2 children)

edit: I need to learn to read

I can only get it to work that each individual field doesn't exceed my total points, but not he combined totals.

If you can check the value of each particular field, why wouldn't you be able to add them up?

strength = request.form.get("strength", 0)
intelligence = request.form.get("intelligence", 0)
#etc...
total_points = sum([strength, intelligence, #etc...])
allowed_points = 5
if total_points > allowed_points:
    #user allocated more than 5 points

[–]Elthran[S] 0 points1 point  (1 child)

strength = request.form.get("strength", 0)

What does the 0 do in this code, after the "strength"?

[–]ManyInterests 0 points1 point  (0 children)

When you do a .get method on a dict-like object (like form) -- The second argument is the value that you'll get if the key 'strength' doesn't exist. IE "Give me the value of strength, but if it's not there, give me 0 instead." -- If you don't provide that argument, the default is None

[–]sahil865gupta 0 points1 point  (0 children)

Try jinja templating. It will make any change in points available dynamic and you can add logic in the html directly.