Form - Field Formatting

From All n One's bxp software Wixi

Revision as of 21:01, 21 November 2016 by Philip Lacey (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

1 Overview

In a form you may like to apply some formatting to your fields. This is often done in tools like Microsoft Word and Excel to tidy up data.


bxp provides a formatting library with numerous functions to help tidy up your data as people perform data entry.


You can also apply sense checks on the data so users can update the information in real time.


This ability does use JavaScript, but as you will see, application can be very easy indeed.


The library is publicly available as https://ww3.allnone.ie/library/javascript/fn_javascript_formatting.js


We don't take credit for coming up with all these amazing functions, so in the source you can see where we got the information to build them from, if it was from out on the net.


2 Functions available

Type Function name Description
String Functions
fn_Formatting_UpperCase(str) Converts the provided string to all capitals
fn_Formatting_LowerCase(str) Converts the provided string to all lower case
fn_Formatting_TitleCase(str) Useful for names and stress addresses, capitalises each word but intelligently jumps over short words, like a, but, in, etc.
fn_Gen_TrimSpaces( strData ) Removes leading and trailing spaces
fn_Gen_String_Left(str, n) Cuts a string if it goes over a certain length (n)
fn_Gen_String_Right(str, n) Keeps last n characters from the right of a string.
fn_General_RemoveAllStrings( strString ) Leaves only numbers
fn_String_ReplaceAllOccurrences(strValue, strReplace) Removes all found instances of strValue from a string
fn_String_ReplaceAllOccurrencesCustom(strValue, strReplace, strReplaceWith) Find and Replace function
fn_Gen_EuroSymbol ( strData ) The proper way to handle a Euro symbol in HTML
fn_General_ReplaceLineBreaksController( strObjectId, strReplaceChar, blShow_Prompt ) Before replacing requests the user to confirm that the return character can be replaced with whatever value is supplied.
fn_General_ReplaceLineBreaks( strObjectId, strReplaceChar ) As above but the prompt is force shown
Number and Currency functions
fn_Formatting_LeadingZeros(num, size) Infinite leading zeros
fn_Gen_LeadingZeros (num, size) Max of eight leading 0s
fn_Formatting_NumbersOnly(value) Leaves only numbers and . characters
fn_Formatting_MinimumDigitsCheck(value, intLength) Strips all non numbers and then counts the numbers, e.g. +353(1)429-4000, will be converted to 35314294000 and then the length checked.
fn_Formatting_FormatMoney(value, n, x, s, c) n: length of decimal, usually 2; x: length of whole part, usually 3; s: sections delimiter, usually ,; c: decimal delimiter, usually .
fn_String_CurrencyCommaFormatting ( strValue ) Strings out dollars, pounds and euros and then reformats the currency amount
fn_String_FormatTwoDecimalPlaces (amount) Ensure sure two numbers after the decimal point
fn_String_FormatCurrencyCommas(amount) Format long currency amounts to have commas, e.g. 1,000,000 for 1 million.
fn_TidyPercent (strString) Flexible function for reformatting VAT amount to be 1.X no matter what the input format
Date functions
fn_Formatting_EuropeanDate(inputFormat) Reformats 14/6/16 to 14/06/2016
fn_Gen_ZuluTime () Gets the current date time in Z2016-06-14T23:40:56 format
Validation functions
fn_isEmail(argvalue) True / False response if email address in string
fn_isDate(dateStr) True / False response if string can be converted to a real date
fn_isApproved(sText, strChars) True / False response for supplied allowed characters in a string
fn_isNumeric(sText) Uses isApproved for numbers and . character
fn_General_MatchMobilePattern( strString ) Using Irish mobiles, hunts for first 8 digit, i.e. works with 35386... and 086, returns everything including the 8
fn_Campaign_PhoneValidate( strHome, strWork, strMobile, strRule ) Three way check for at least one valid phone number from three different sources.
fn_General_ValidatePhone_Explicit_Irish ( strPhoneField, blIsMobile, blReplaceWithClean ) Complex phone sense checking function capable of handling all Irish numbers
fn_General_ValidatePhone_Irish ( strPhoneField, blReplaceWithClean, blReplaceWithBlank ) The ability to check and also clean in one function
fn_Formatting_IsUKPostCode(postcode) Recently updated algorithm for checking UK postcodes
fn_isUKPostCode(addressStr) Older approach to UK post codes.


3 Usage of formatting

The simplest way of using the formatting is to edit the "onchange" of any question.


Click the pencil icon to the right of the field you want to edit. Find the onchange box. Add in the following for example.


this.value = fn_Formatting_UpperCase ( this.value );


Go down the bottom and "update" the question.


Now when you type something in the box... and move out of the box, the function will update the contents. Hey presto... formatting.