On Apr 11, 11:49 pm, JorgeRpo <[email protected]> wrote:
> what is ingredient_num for?

It's to keep track of what order the ingredients are in- recipes
usually list ingredients in the order you will use them.


On Apr 12, 1:14 am, pbreit <[email protected]> wrote:
> I'd suggest something like this:

That's essentially what I planned to do to display recipes, although
you removed the "units" table, which I require to do unit conversion
later.

The part I'm stuck on is making a form to enter a recipe into the
database. Web2py's FORM/SQLFORM/SQLFORM.factory functions all assume
your form is static, but mine is not. I need to show a set of fields
to the user (ingredient, quantity, and unit of measure), and allow the
user to click a button labeled "Add another ingredient" and have an
additional set of those same fields appear on the same form. I've
gotten close to this using FORM and JavaScript, but I keep running
into a few problems:

1) Some of Web2py's validators (e.g. IS_MATCH) don't like receiving
lists in the "value" argument instead of strings, which is what
happens when you have a bunch of fields all named "ingredient_name".

2) When I create the FORM object in my controller, it only has one set
of fields for a single ingredient. If I add more fields in JavaScript,
then the user fills out the form incorrectly, my controller gets the
form, says "oh, look, errors!", and sends the form back to the user
with only a single set of fields, instead of fields for all of the
ingredients the user typed in.

3) I need validators to work conditionally. If the user puts something
into the "ingredient_name" field, they must also put something into
the "quantity" field. However, if the user clicks "Add another
ingredient", but doesn't fill out any of those fields, the form should
be accepted.

Reply via email to