How to make user input uppercase in any extjs 4 / 3 textbox / field components

Here’s a really quick one, I write a lot of code that requires the user enter the data into textfields in upper case only, but really do I have to assume that they will remember to hit the caps lock key or the shift key every time they enter that field? The following will make the text ‘appear’ to be in upper case when entered on the client side. You will have to convert the text into upper case before submission to the server side database using your database’s built-in uppercase method.

{
xtype: 'textfield',
fieldLabel: 'Some Field',
maxLength:2,
minLength:2,
fieldStyle:'text-transform:uppercase', // This does the trick
enforceMaxLength:true, // Stops characters like old html maxlength
allowBlank: false
}

Minimizing your javascript using the YUI compressor

Once you code your masterpiece, by of course using descriptive variable names, function names, and fully indented and commented code, you are ready to upload it to your web server and put your application into production. That’s great! But all of those descriptive variable names, tabs, spaces, and eloquent coding are increasing your javascript file size. So what, right, it’s only a few bytes, how much could that harm? Well, when a user requests a page from the server they are actually requesting all of the elements (like pictures, stylesheets, javascript, flash files, etc ..) to be downloaded individually, unless some of the elements have been stored on the client’s machine. The files that are stored are in the user’s cache. Here’s the issue, most of the users that hit a site have an empty cache according to research done by Yahoo’s performance team. http://developer.yahoo.com/performance/ This is exactly why it is so important to keep your files as lightweight as possible, meaning, compress those images, and now compress those external javascript files and css files. So what does code minimization do? First, it strips out any of the comments and blank spaces, next it rewrites the variable, object, and function names using names that are as short as possible. The result is a file with one line of javascript that is usually 20% to 40% smaller than the previous file.

How to minimize your files:

  • Download the YUI Compressor http://developer.yahoo.com/yui/compressor/
  • Extract the files to your hard drive, for example let’s say you use C:/ as the location.
  • Now run your code through the compressor by

  • open the command prompt in Windows and navigating to the folder C:/yuicompressor-2.4.6/build/
  • Copy your javascript file into the ‘build’ folder in the location above
  • Run this command in the command prompt window: java –jar yuicompressor-2.4.6.jar –your_filename_here.js –o your_filename_here-min.js
  • You should now have your source file your_filename_here.js and the minimized file your_filename_here-min.js in the build folder.
  • Cut and paste the minimized folder to your test server and try to break it
  • But wait that’s not all …

    If you read the previous article on speeding up your application you also know that scope and how you manage it could cause additional delays. In addition, with all those changes did you really go line by line and see what code your modifications may have rendered ‘dead code’, or unused code?

  • Use -v like this to output all of the dead code and scope errors in your javascript java –jar yuicompressor-2.4.6.jar –your_filename_here.js –o your_filename_here-min.js -v
  • Finally, you could view JavaScript minification as a way of security through obscurity, which will make it harder for someone to reverse engineer your code and could be used in a ‘defense in depth’ approach to security as I would not recommend this as your only line of defense.

    Pattern recognition app as an example of Sencha Animator

    Recently I took a trip and met some of my relatives that live in Shanghai, they have a small child and the Glenn Doman pattern recognition cards are very popular in China, so I thought I would write an app and put them on the internet so that you can learn the numbers in Mandarin and our Western character set as well as pattern recognition. Truth be told I wanted to test drive Sencha’s animator as well so I got started and discovered the following bug (but since it’s a beta product it is to be expected), take a look at the series of dots below, figures 1 – 4 are done using the scale method, and appear flawless in the application, however, when translated to the browser they are quite blurry. Figure 5 uses pixel size as the setting and they difference is crystal clear characters, it appears that the scale feature is not working, that said, the product puts out webkit HTML 5 / CSS 3 code that runs in modern browsers and of course on all out mobile devices. The app is much easier to use than Flash, and without plugins there is really no reason to use Flash again. Look for the app in the market soon! If you don’t have an HTML 5 compatible browser then your’e out of luck!

    The Sencha Animator Page

    A really fuzzy 4 using the scale in Sencha Animator

    A really clear 5 using a pixel size instead of scale

    Using div tags, CSS, and Image Sprites to create a rounded box for your content

    One popular design feature of many sites these days continues to be a section of framed content in a box. Some examples include the boxes that you can see on sites like CNN, or twitter just to name a few.

    A framed content box that is shown on twitter

    A framed content box that is shown on twitter

    CNN's take on the framed box

    CNN's take on the framed box

    This is a perfect example of how to use nested div tags to create such an effect that has the ability to scale in width so there is no need to change the top image every time you decide to change the width of the page. If you are new to html and css you probably read the title of the article and wondered to yourself what sprite has to do with any of this, right? Sprites are a series of images that have all been combined in one image, make sense? See when you design a user interface for a website some elements are bound to be repeated over and over again, and you may want to cut doen on the round trips to the server that are made when a resource like an image is requested by the browser, the answer is creating a sprite, or a collage of all the images that will be used by the interface in ‘background-image’ css declarations. Just like the screen the coordinates 0,0 are given to the top left hand pixel of an image, therefore you can pick just the slice of a large image that you want to show in the background of a div tag. A good example would be the left hand corner below, see you start at 0 pixels from the left and 0 pixels from the top (‘background: url(‘../../testsomethings/images/bg_sprite.gif’) 0px 0px;’ ) which happens to be right where the left hand curve is at, then you go 9 pixels wide and done. For the right we use the same image but we start from the far right and go 9 pixels back toward the left ( background: url(‘../../testsomethings/images/bg_sprite.gif’) -352px 0px; ). Now for the center piece we have to go down 100 pixels from the top or else we will see the curve appear in the center box, so we use ( background: url(‘../../testsomethings/images/bg_sprite.gif’) 0px -100px ; )

    You can see that the classes involved in box include:

    • roundedbox – this is the container that holds the entire box
    • header – this is the top of the box and it contains the left corner, right corner, and center sections of the round box.
    • leftCorner – this holds the left hand corner so that the background image will give the box the effect of being rounded.
    • rightCorner – this holds the right hand rounded image in the background
    • center - this is the repeating center image and also contains the heading which has been placed in a h2 tag with the font properties adjusted for readability.
    • content – this div holds the actual story content and contains the gradient grey background slice which fades into white.

    You can see the code below here ( http://www.learnsomethings.com/testsomethings/rounded_corners.html ).

    You can see the sprite here, but you could probably do a much better job matching the boxes yourself ( http://www.learnsomethings.com/testsomethings/images/bg_sprite.gif ).

    The CSS

    <style>
    .roundedbox .header {
                    position: relative;
                    height: 33px;
                    width: 100%;
                    z-index: 200;
    }
    
    .roundedbox .header h2 {
                    font-size: 16px;
                    color:#FFF;
                    font-weight:200;
                    margin-left: 3px;
                    margin-top: 3px;  
                    display: inline;
                    float: left;  
                    font-family:Verdana,sans;
    }
    
    .roundedbox .leftCorner {
                    background: url('../../testsomethings/images/bg_sprite.gif') 0px 0px;
                    height: 33px;
                    width: 9px;
                    position: absolute;
                    left: 0;
                    top: 0;
    }
    
    .roundedbox .center {
                    background: url('../../testsomethings/images/bg_sprite.gif') 0px -100px ;
                    height: 33px;
                    position: absolute;
                    left: 9px;
                    right: 9px;
    }
    
    .roundedbox .rightCorner {
                    background: url('../../testsomethings/images/bg_sprite.gif') -352px 0px;
                    height: 33px;
                    width: 9px;
                    position: absolute;
                    right: 0;
                    top: 0;
    }
    
    .roundedbox {
                    position:relative;
                    display:block;
                    float:right;
                    margin:8 8 8 8;
                    padding: 0;
                    width:100%;
    }
    .content {
                    position:relative;
                    display:block;
                    background: #fff url('../../testsomethings/images/widgetBG.gif') bottom repeat-x;
                    padding:6px 10px 6px 10px;
                    font-family:Verdana,sans;
                    font-size:12px;
                    line-height:1.4em;
                    list-style-type: disc;
    }
    </style>
    

    The html that is required to make one of the boxes to the left consists of several div tags to comprise the various parts of the container.

    The HTML code

    <div class="roundedbox" >
                    <div class="header">
                      <div class="leftCorner"><!-- I'm just here to make
                            the left corner rounded--></div>
                      <div class="center">
                            <h2 title="" role="complementary">Headline News</h2>
                      </div>
                      <div class="rightCorner"><!-- I'm just here to make
                            the right corner rounded--></div>
                    </div>
           <div class="content" >
                 <p>Some great content would normally go here, and
                   maybe even a thumbnail image!<b>Read More ... </b>
                 </p><br />
           </div>
    </div>
    

    What you should know after the first HTML class:

    What you should know after the first class:

    First of all you can find a complete listing of tags at http://www.w3schools.com/html5/html5_reference.asp

    There is a complete listing of CSS values at http://www.w3schools.com/css/css_reference.asp

    Html is a series of tags, they start with a < followed by the tag name, a space then the attribute followed by an = sign and the attribute value in “ “ quotes. They are then closed by a >

    There are two types of tags, self closing, or those which hold no content between   them such as:

    <img src=”somepicture.jpg” />
    

    and those that contain content between the opening and closing tags such as,

    <a href=”somepage.html” > This is a link! </a>
    

    There are four tags that you must have in your page

    
    <html>
     <head>
     </head>
     <body>
     </body>
    </html>
    
    

    CSS or cascading style sheets control the display of the page.

    An example of a class:

     .name {
     attribute1:property;
     }
    

    An example of a rule (applies to all tags):

     p  {
     attribute1:property;
     }
    

    We have set up an account on a server that hosts your websites that you will be creating throughout the course, when you get home the method by which you will access the files on this site is:

    1) Open Aptana
    2) Right click on the ‘projects’ folder (see image below)

    Right click on the projects folder and select add new project

    Right click on the projects folder and select add new project.

    3) Select existing hosted project (see image below):

    Select existing hosted project

    Select existing hosted project

    4) Choose default location and press next
    5) Give your project a name (see image below):

    Give your project a name and press 'next'

    Give your project a name and press 'next'

    6)Click on the ‘new connection’ button and complete the blanks using the site information that you received from www.freewebhostingarea.com

    Now click on the new connection button, fill in the information and watch your site appear!

    Now click on the new connection button, fill in the information and watch your site appear!