Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Text Formatting

Locked
barrydocks
Posts: 18
Joined: Wed Dec 18, 2013 4:44 pm

Text Formatting

Unread post 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
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Text Formatting

Unread post 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:
    Example to format text field to uppercase
    Example to format text field to uppercase
    onBlurEvent.png (4.66 KiB) Viewed 5739 times
  • 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
barrydocks
Posts: 18
Joined: Wed Dec 18, 2013 4:44 pm

Re: Text Formatting

Unread post 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
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Text Formatting

Unread post 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
barrydocks
Posts: 18
Joined: Wed Dec 18, 2013 4:44 pm

Re: Text Formatting

Unread post by barrydocks »

Max,

Thanks for your help.
A
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Text Formatting

Unread post by massiws »

.
Locked