org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/TextField.js
changeset 309 c01f5ab28a11
parent 308 c521df56b15d
child 310 e9484be98cfe
equal deleted inserted replaced
308:c521df56b15d 309:c01f5ab28a11
     1 /**
       
     2  * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  * 
       
    12  * Contributors:
       
    13  * 
       
    14  * Description:
       
    15  * 
       
    16  */
       
    17 
       
    18 ///////////////////////////////////////////////////////////////////////////////
       
    19 // The TextField class implements a single line text entry control.
       
    20 
       
    21 // Constructor.
       
    22 function TextField(id, caption, value, masked) {
       
    23     if (id != UI_NO_INIT_ID) {
       
    24         this.init(id, caption, value, masked);
       
    25     }
       
    26 }
       
    27 
       
    28 // TextField inherits from TextEntryControl.
       
    29 TextField.prototype = new TextEntryControl(UI_NO_INIT_ID);
       
    30 
       
    31 // Initializer - called from constructor.
       
    32 TextField.prototype.init = function(id, caption, value, masked) {
       
    33     uiLogger.debug("TextField.init(" + id + ", " + caption + ", " + value + ", " + masked + ")");
       
    34     
       
    35     // call superclass initializer
       
    36     TextEntryControl.prototype.init.call(this, id, caption);
       
    37     
       
    38     // create the peer element
       
    39     this.peerElement = document.createElement("input");
       
    40     this.peerElement.type = masked ? "password" : "text";
       
    41     this.controlElement.appendChild(this.peerElement);
       
    42     
       
    43     // set the value
       
    44     this.peerElement.value = (value == null) ? "" : value;
       
    45     
       
    46     // bind event listeners
       
    47     this.bindTextEntryControlListeners();
       
    48     
       
    49     // update the style
       
    50     this.updateStyleFromState();
       
    51 };
       
    52 
       
    53 // Updates the style of the control to reflects the state of the control.
       
    54 TextField.prototype.updateStyleFromState = function() {
       
    55     uiLogger.debug("TextField.updateStyleFromState()");
       
    56     
       
    57     // determine the state name
       
    58     var stateName = this.getStyleStateName();
       
    59     
       
    60     // set element class names
       
    61     this.setClassName(this.rootElement, "Control");
       
    62     this.setClassName(this.controlElement, "ControlElement");
       
    63     this.setClassName(this.assemblyElement, "ControlAssembly ControlAssembly" + stateName);
       
    64     this.setClassName(this.captionElement, "ControlCaption ControlCaption" + stateName);
       
    65     
       
    66     // set peer element class names
       
    67     var peerStateName = this.isEnabled() ? stateName : "Disabled";
       
    68     this.setClassName(this.peerElement, "TextField TextField" + peerStateName);
       
    69 };