Page 1 of 1

How to do I capitalise the first letter of each word on entry to the database?

Posted: Sun Jul 05, 2015 8:00 pm
by Dan Coates

How do you convert input box value to capitalise the first letter of each word? I know

.CapitaliseInput {
text-transform:capitalize;
}

Will do the visual aspect, but that won't' save the value as capitalised into the database, is it possible to do an update on the database as it's sent to transform it? or invoke some other command?

I'm stumped and don't know what I need to do.

Any help appreciated.


How to do I capitalise the first letter of each word on entry to the database?

Posted: Mon Jul 06, 2015 7:41 pm
by Illya Stepanov

Hi Dan -

For such cases you can use mapping from input component and modify values from it with any custom JS code, like for example shown here: https://devcenter.appery.io/documenta...


How to do I capitalise the first letter of each word on entry to the database?

Posted: Mon Jul 06, 2015 9:00 pm
by Dan Coates

You guys are not very good at giving examples are you! that page doesn't give a very good example.

return value.toUpperCase();

This makes all words full caps.

Also how would I get it to capitalise only the first letter of each word? Is there a Capitalise command? or anywhere with a list of Jquery commands that work with appery.

Dan


How to do I capitalise the first letter of each word on entry to the database?

Posted: Tue Jul 07, 2015 7:24 pm
by Dan Coates

Solved it!, for anyone in the future who stumbles upon this question, here is the answer. Place the following into a new javascript file in the project.

String.prototype.toTitleCase = function() {
var i, j, str, lowers, uppers;
str = this.replace(/([\W_]+[\s-]*) */g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});

// Certain minor words should be left lowercase unless
// they are the first or last words in the string
lowers = ['A', 'An', 'The', 'And', 'But', 'Or', 'For', 'Nor', 'As', 'At',
'By', 'For', 'From', 'In', 'Into', 'Near', 'Of', 'On', 'Onto', 'To', 'With'];
for (i = 0, j = lowers.length; i < j; i++)
str = str.replace(new RegExp('\\s' + lowers + '\\s', 'g'),
function(txt) {
return txt.toLowerCase();
});

// Certain words such as initialisms or acronyms should be left uppercase
uppers = ['Id', 'Tv'];
for (i = 0, j = uppers.length; i < j; i++)
str = str.replace(new RegExp('\\b' + uppers + '\\b', 'g'),
uppers.toUpperCase());

return str;
}

and then call it on your database input/output as per the examples giving in the tutorial page listed above, using the following:

return value.toTitleCase();

This will capitalise the first letter of every word in the input box, and not capitalise certain minor words.


How to do I capitalise the first letter of each word on entry to the database?

Posted: Tue Jul 07, 2015 7:53 pm
by Evgene Karachevtsev

Hello Dan,

Thank you for the update!