Widget accepts "1/2," but on save generates error and abandons changes.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mropanen’s picture

To fix this, I added this to recipe_ingredient_autocomplete_validate

if (empty($element['quantity']['#value'])) {
    if (empty($element['unit_key']['#value']) && empty($element['name']['#value']) && empty($element['note']['#value'])) {
      // this is okay, continue
    }
    else {
      form_error($element['quantity'], t('Please enter quantity of ingredient'));
      return;
    }
  }
  elseif (!is_numeric($element['quantity']['#value'])) {
    form_error($element['quantity'], t('Quantity must a whole number (such as 3) or a decimal (such as 3.25). Note that you must use the period symbol (.) not comma (,). Fractions (3 1/4) are also not supported.'));
  }
  else {
    // what then?
  }

(The long if-empty line is there to make sure we can actually delete an ingredient by emptying all the fields :)

dcam’s picture

Title: Quantity Fractions, ie "1/2" error » Saving fractional ingredient quantities results in database error
Issue summary: View changes
FileSize
3.65 KB
2.83 KB

The ingredient field conversion missed an important step in processing form input, converting fractional quantities to decimal. Entering a fractional quantity in the field will cause Drupal to try and save the text to the float database field, resulting in a database error.

This patch should fix the error.

dcam’s picture

Status: Active » Needs review

Forgot to set the status.

Status: Needs review » Needs work

The last submitted patch, 2: fraction-quantity-error-2117783-2-tests-only.patch, failed testing.

dcam’s picture

Title: Saving fractional ingredient quantities results in database error » [REGRESSION] Saving fractional ingredient quantities results in database error
Status: Needs work » Needs review
FileSize
3.55 KB

Minor edit. I moved the function in recipe.module.

  • Commit 103727d on 7.x-2.x by dcam:
    Issue #2117783 by dcam: Regression: Saving fractional ingredient...
dcam’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.