Not signed in (Sign In)

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthoriamfabian
    • CommentTimeMar 31st 2008
     
    Is it possible to restrict users to enter things in in Title Case and not ALL CAPS?

    Is there a Javascript to control this?

    I want to prevent users from entering info all in lower case or ALL CAPS!
    • CommentAuthordbuschho
    • CommentTimeMar 31st 2008
     
    I dont think it's too possible to do when they are actually typing. But it may be possible to convert what they type to title case when they leave an input box. Let me look into it.
    • CommentAuthordbuschho
    • CommentTimeMar 31st 2008
     
    Actually one can do that apparently. Give this a try, same deal as before, put into the code box, and you have to provide it with each field you want the specialness on. Let me know if it works.

    <script type="text/javascript">
    function toTitleCase(str)
    {
    //http://efficienttips.com/convert-string-title-case-javascript/
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
    }
    function addTitle(source)
    {
    if(!(document.querySelector)){base2.DOM.bind(document);}
    document.addEventListener('DOMContentLoaded',
    function(){
    document.querySelector("#"+source).addEventListener("keypress",function(){this.value=toTitleCase(this.value);},false);
    }
    }

    addTitle(MyFieldID);
    </script>
    • CommentAuthoriamfabian
    • CommentTimeMar 31st 2008
     
    do i just alter the addTitle(MyFieldID) to something like:

    addTitle(tfa_FirstName)


    thanks!
    • CommentAuthordbuschho
    • CommentTimeMar 31st 2008
     
    whoops, yup (I think you need quotes though)

    addTitle("tfa_FirstName");
    • CommentAuthordbuschho
    • CommentTimeMar 31st 2008
     
    Whoops, to anyone reading this,
    the line
    //http://efficienttips.com/convert-string-title-case-javascript/
    should not be included.
  1.  
    There are a parenthesis and semicolon missing from the code above --- I got it to work as follows:

    <script type="text/javascript">
    function toTitleCase(str) {
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
    }

    function addTitle(source) {
    if(!(document.querySelector)){base2.DOM.bind(document);}
    document.addEventListener('DOMContentLoaded',
    function(){
    document.querySelector('#'+source).addEventListener('blur',function(){this.value=toTitleCase(this.value);},false);
    });
    }

    addTitle('tfa_Firstname');
    </script>