Name for a numeric form element?

Events happening in the community are now at Drupal community events on www.drupal.org.
markus_petrux's picture

Sometime ago I wrote Format Number API and Formatter Number CCK modules. The former implements options at site/user level to define thousands separator and decimal point, also provides APIs to display numbers. The later implements CCK fields for different types of numbers. These CCK fields implement their own numeric form element based on textfield. Too bad! I should have implemented in Format Number API a form element for numbers at FAPI level. It was kind of too late when I figured this out, and well, I have never needed such a FAPI element, except now. I need that for a custom application that does not use CCK, so I'm going to work on it...

My problem is... which name for a numeric form element at FAPI level?

a) 'formatted_number' is taken by Formatter Number CCK, and I would prefer not to add more version dependencies between that module and Format Number API.
b) 'number' is taken by the CCK Number field (CCK2 and also Fields in D7).
c) 'numeric'?

I believe I'll opt for c) 'numeric'. I think no one else is using this name for a FAPI element? Hard to search for these words. :(

Any other suggestion?

Related issue in the Format Number API queue: http://drupal.org/node/438116

Comments

A couple more options...

markus_petrux's picture

The name for text input elements in FAPI is 'textfield', CCK Text field uses 'text'. So, if CCK uses 'number' for Number fields, what we need is 'numberfield' for a FAPI form element.

hmmm...

d) 'numberfield' ?
e) 'numericfield' ?

Arg! I'm going mad with this.

'numeric' is short, 'numberfield' or 'numericfield' look more like 'texfield' and these seem easier to scan in source files.

'numberfield' could still be confused with 'number' in CCK2 of Fields in D7, so maybe the best option is 'numericfield' ?

Well, I opted for numericfield

markus_petrux's picture

...and this stuff has been committed to CVS.

Related issue: Implement numeric input element at Forms API level.

Documentation can be found in the README.txt shipped with the module. Here's a copy/paste of the section related to this new Forms API element:

FORMS API NUMERIC ELEMENT
=========================

The 'numericfield' Forms API element provides a right aligned text input
element that allows the user enter numbers using the configured thousands
separator and decimal point (site default or user defined).


Example:

$form['my_number'] = array(
  '#type' => 'numericfield',
  '#title' => t('My number'),
  '#precision' => 10,
  '#decimals' => 2,
  '#minimum' => 0,
  '#maximum' => 123456.99,
  '#default_value' => $my_number,
);


Specific Forms API attributes for elements of #type 'numericfield':

- #precision:
  Integer that indicates the total number of digits available to store the
  number, including the digits to the right of the decimal point.
  Defaults to 12.

- #decimals
  Integer that indicates the number of available digits to the right of
  the decimal point.
  Defaults to 0. Maximum allowed number of decimal digits: 8.

- #minimum
- #maximum
  Minimum and maximum possible values that are allowed on input.


Other Forms API supported attributes for elements of #type 'numericfield':

- #title
- #description
- #attributes
- #field_prefix
- #field_suffix
- #prefix
- #suffix


Theme function used to render the form element:

- theme_numericfield($element)


CSS Class attached to numeric form elements:

- form-numeric (defined in format_number.css).

Form API

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: