function _fraction_decimal_widget_validate in Fraction 7
Validation function for the fraction_decimal widget to convert the decimal to a fraction.
1 string reference to '_fraction_decimal_widget_validate'
- fraction_field_widget_form in ./
fraction.field.inc - Implements hook_field_widget_form().
File
- ./
fraction.field.inc, line 281 - Fraction Field API functions
Code
function _fraction_decimal_widget_validate($element, &$form_state) {
// Search through the form values to find the current field value.
$parents = $element['#parents'];
$values = drupal_array_get_nested_value($form_state['values'], $parents);
// If the decimal is not an empty string, convert the value to a fraction.
if (trim($values['decimal']) !== "") {
$fraction = fraction_from_decimal($values['decimal']);
$values['numerator'] = $fraction
->getNumerator();
$values['denominator'] = $fraction
->getDenominator();
}
// Set the numerator and denominator values for the form.
form_set_value($element, $values, $form_state);
}