Page 1 of 1

Text Formatting

Posted: Sun Jan 19, 2014 5:33 pm
by barrydocks
How can I make text on a new record enter the data in to the database with a specific format? ie ALL CAPS or Title Case

I have worked out how to format displayed text with styles but not how to format it on data entry.

Thanks

Re: Text Formatting

Posted: Mon Jan 20, 2014 11:25 pm
by massiws
barrydocs,
you could use Javascript to validate/format fields.
Two ways:
  • for single field with simple format you can use On Blur event on the object:
    onBlurEvent.png
  • for many fields and/or more complex formats, you can build a JavaScript function in Custom Code > Javascript and use both OnBlur event and nuBeforeSave() function:

    Code: Select all

    /*
     * Check data validity and format text field
     */
    function nuBeforeSave() {  
        return (
            validateField('my_first') 
            && myCustomFormat('my_second')
            //... 
        ) ? true : false);
    }
    
    function validateField(fieldName) {
        // Check data validity
        
    }
    
    function myCustomField(fieldName) {
        // Apply custom format
        
    }
Hope this helps,
Max

Re: Text Formatting

Posted: Tue Jan 21, 2014 9:53 pm
by barrydocks
Max,

Thanks for the reply. As you might have guessed from the very basic nature of the questions I am asking, I am pretty new to this. I am still struggling with mysql and php, I think JavaScript is a way out of my skill set at present :oops:

Anyway, please would you be so kind as to give a brief breakdown of the 2 script examples you have suggested so that I might have an idea where to start?

Thanks
Adrian

Re: Text Formatting

Posted: Wed Jan 22, 2014 7:46 pm
by massiws
Adrian, to format a field on data entry you have to:
  • login as globeadmin;
  • open the form in Edit screen;
  • double-click on the label of the field you want to format: this open a new window on the object (the same window can be opened in Setup > Objects > <your-object>);
  • in All tab > On Blur field you have to enter the Javascript (or, better, jQuery) code to execute when the user leave the field; so, if you enter this jQuery code:

    Code: Select all

    $(this).val($(this).val().toUpperCase());
    when the user leave the field the text he/her entered is being transformed in uppercase;
  • depending on what format you have to apply, the JavaScript (or jQuery) code is different; this is for Title Case:

    Code: Select all

    $(this).val($(this).substring(0,1).toUpperCase()+$(this).substring(1));
Here you can find a starting point.

Max

Re: Text Formatting

Posted: Wed Jan 22, 2014 10:50 pm
by barrydocks
Max,

Thanks for your help.
A

Re: Text Formatting

Posted: Wed Jan 22, 2014 11:33 pm
by massiws
.