Suggestion: [New Plugin] Numeric Field type

More
10 years 6 months ago - 10 years 6 months ago #47360 by AboutUtila
UPDATE 12-Jun-2014: Partial Solution found - See Modified Text Field Plugin with number formatting post below.

I'm working on a new Joomla! (3.x and later) project.
I've chosen to try out FlexiContent - looks very promising - Thank you.
This is my first forum post - I've searched the Forum and elsewhere for a solution to the following, but no success.

Suggestion:
In addition to the existing "Text (number/time/etc/custom validation" Field type,
I am suggesting you provide a new single property "Numeric" Field type which stores a number as a PHP Floating Point number (rather than a string),
and provides 'Display Parameters' supporting (as a minimum) all four parameters of PHP number format (refer www.php.net/manual/en/function.number-format.php ),
or, perhaps for more flexibility,
the PHP money_format (refer: www.php.net/manual/en/function.money-format.php ),
and,
with input validation of the number types/representations (refer en.wikipedia.org/wiki/List_of_types_of_numbers ) supported by this suggested new FlexiContent 'Numeric' field.

For example;
Positive/Negative numbers (allow/disallow)
Natural Number (zero not allowed),
Integer Number (Natural Numbers including zero),
Decimal (Rational Number).

My project 'Numeric Field' requirements are:
(a) Input/Store a Decimal number with values before and after decimal point, i.e.;
100000.001
100000000.00001
1.1
(b) validate number input is a valid decimal number,
(c) Display 'user friendly' 'formatted number' on output using different 'decimals' and thousands_sep
i.e.;
input & validate a decimal number with value = 100000.0004
then display number as;
100,000.00 or
100.000.00 (Spanish Notation) or
100 000,00 (French Notation) or
100,000.0004 (PHP money_format with; suppress the currency symbol and Left precision = 4n)
(d) Create a 'filter/Smart Search' that can operate on FlexiContent Floating Point field 'Numeric' number ranges as opposed to Text string numbers;
i.e Search on Items with "Numeric" Field type; min value = 0, max value = 10,00

Why?
Essential to Input/Store a Floating number (rather than a 'string') for formatted display of numerics such as Price, Length, Area, Volume, Weight, Ratio, etc, and providing 'filter/Smart Search' on Floating number value ranges in 'types' such as catalog, directory, etc.

Does this make sense to you?

Regards - Mark
Also see;
www.flexicontent.org/forum/index.php?f=20&t=7484&rb_v=viewtopic
www.flexicontent.org/forum/index.php?f=30&t=5227&rb_v=viewtopic
www.flexicontentcck.org/forum/index.php?...=2271&rb_v=viewtopic
code.google.com/p/flexicontent/issues/detail?id=230
www.flexicontent.org/forum/index.php?f=3...rt=10&rb_v=viewtopic
www.flexicontent.org/forum/index.php?f=3...rt=10&rb_v=viewtopic
www.flexicontent.org/forum/index.php?f=2...b_v=viewtopic#p33253

Joomla: Joomla! 3.3.0 Stable, Joomla Platform 13.1.0 Stable
FlexContent: 2.2.0 r1910 Beta
Last edit: 10 years 6 months ago by AboutUtila.

Please Log in or Create an account to join the conversation.

More
10 years 6 months ago #47363 by micker
i think you can do it for your project .. dupolicate and edit a plugin to create own
read this How to Duplicate a Flexicontent Field to create a new Field Type

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
10 years 6 months ago #47377 by AboutUtila
Thank you,

I will give it a try and post back the plugin files as an attachment when/if I get it working.

Your instructions
How to Duplicate a Flexicontent Field to create a new Field Type are clear enough, but it's been a while since I've written PHP code and customized Joomla!.

Thanks again.

Joomla: Joomla! 3.3.0 Stable, Joomla Platform 13.1.0 Stable
FlexContent: 2.2.0 r1910 Beta

Please Log in or Create an account to join the conversation.

More
10 years 6 months ago #47382 by ggppdk
Hello

- the current validation of the text field, includes option "Decimal"

so this should cover your need value validation in form (a + b)


and you can have range search in filtering (d)
- set field parameter "Filter value comparison"to "Numerical"



so maybe a,b,d is covered by existing text field,


but (c) appearance according to current frontend language is surely not covered by existing options of text field


-- so you could, duplicate text field and try to change only the function "onDisplayFieldValue"

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
10 years 6 months ago #47640 by AboutUtila

duplicate text field and try to change only the function "onDisplayFieldValue"

Thank you for your guidance.

I have modified the standard v1.0 text field so that it will display (but not store) decimal and integer numbers with some basic formatting. The formatting is only applied to text fields with 'Value Validation Mask' parameter = Decimal or Integer.
This is useful for displaying fields for Price, Length, Area, etc.
Because the decimal and integer numbers are not stored with formatting, sorting/ordering and range filters are unaffected.

The formatting;
- number of digits to display after the decimal point (default = 0)
- character to use as thousands separator (default = , [comma])
- character to use as decimal point (default = . [period])
is specified in the configuration of the text field parameters.

This is what I did and it seems to work OK.
In text.php v1.0 at around line 325
Changed From;
Code:
if !strlen($value) ) continue; $field->{$prop}[$n] = $pretext.$value.$posttext
Changed To;
Code:
if !strlen($value) ) continue; // Start MCS_Hack for number formatting if ($field->parameters->get('inputmask')=='decimal' or $field->parameters->get('inputmask')=='integer'){ $num_of_decimals = (int)$field->parameters->get('num_of_decimals', 0); $decimal_separator = $field->parameters->get('decimal_separator', '.'); $thousands_separator = $field->parameters->get('thousands_separator', ','); $value = number_format(floatval($value),$num_of_decimals,$decimal_separator,$thousands_separator); } // End MCS_Hack for number formatting $field->{$prop}[$n] = $pretext.$value.$posttext

And in text.xml at around line 62
Changed From;
Code:
<field name="closetag" type="text" default="" size="50" label="FLEXI_FIELD_CLOSING_TEXT" description="FLEXI_FIELD_CLOSING_TEXT_DESC" /> <field name="" type="separator" default="FLEXI_SOCIAL_SUPPORT" description="FLEXI_SOCIAL_SUPPORT_IMG_DESC" level="level2" />

Changed To;
Code:
<field name="closetag" type="text" default="" size="50" label="FLEXI_FIELD_CLOSING_TEXT" description="FLEXI_FIELD_CLOSING_TEXT_DESC" /> <!-- Start MCS_Hack Formatted Numeric field parameters --> <field name="" type="separator" default="FLEXI_FORMATTED_NUMBER_SEPARATOR_LABEL" description="FLEXI_FORMATTED_NUMBER_SEPARATOR_LABEL_DESC_FIELD" level="level2" /> <field name="num_of_decimals" type="text" size="6" default="0" label="FLEXI_FORMATTED_NUMBER_NUM_DECIMALS_LABEL" description="FLEXI_FORMATTED_NUMBER_NUM_DECIMALS_DESC" /> <field name="decimal_separator" type="text" size="1" default="." label="FLEXI_FORMATTED_NUMBER_DECIMAL_POINT_LABEL" description="FLEXI_FORMATTED_NUMBER_DECIMAL_POINT_DESC" /> <field name="thousands_separator" type="text" size="1" default="," label="FLEXI_FORMATTED_NUMBER_THOUSANDS_SEPARATOR_LABEL" description="FLEXI_FORMATTED_NUMBER_THOUSANDS_SEPARATOR_DESC" /> <!-- End MCS_Hack Formatted Numeric field parameters --> <field name="" type="separator" default="FLEXI_SOCIAL_SUPPORT" description="FLEXI_SOCIAL_SUPPORT_IMG_DESC" level="level2" />

I attach a text field installation package containing the modifications.
Note: This package also includes a modification to text.xml Line 3.
Changed From:
<name>FLEXIcontent - Text (number/time/etc/custom validation)</name>

Changed To:
<name>FLEXIcontent - Text (number/time/etc/custom validation) with custom hack for formatting numbers</name>

and a modified en-GB.plg_flexicontent_fields_text.ini language file for the additional number formatting parameters

Thank you again.

Joomla: Joomla! 3.3.0 Stable, Joomla Platform 13.1.0 Stable
FlexContent: 2.2.0 r1910 Beta
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.533 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline