How can I edit this code to make "This name input field" to be "This Name Input Field"? Can anyone give me a light? :)
EDIT: I'm really noob, I don't know nothing about javascript, just trying to edit this code to get first letters capitilized.
function wpf_dev_capitalize() {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery( '.wpforms-field.capitalize input' ).keyup(function() {
jQuery(this).val(jQuery(this).val().substr(0,1).toUpperCase() jQuery(this).val().substr(1).toLowerCase());
});
jQuery( '.wpforms-field.capitalize textarea' ).keyup(function() {
jQuery(this).val(jQuery(this).val().substr(0,1).toUpperCase() jQuery(this).val().substr(1).toLowerCase());
});
});
</script>
<?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_dev_capitalize', 30 );
CodePudding user response:
const capitalize_first_letter = string =>{
let stringArr = string.split(' ');
return stringArr.map(word=>{
let splitWord = word.split('')
let capitalized = splitWord[0].toUpperCase();
splitWord.shift();
splitWord.unshift(capitalized)
return splitWord.join('')
}).join(' ');
}
CodePudding user response:
To avoid reinventing the wheel, one possible solution is just use something like lodash (as a "standard library") in the project for every trivial cases in your project like this:
import { startCase } from "lodash";
console.log(startCase("This name input field")); // This Name Input Field