TextBox

Deprecation Warning! The content below is only applicable for use within deprecated 1.x versions of CA Agile Central's App SDK. Use of the component(s) and/or code on this page is not supported. To develop custom apps within our current environments, please see App SDK 2.0 documentation.

The TextBox component provides an easy way to create a stateful text box and label.

text box

TextBox includes the following topics:

Create a text box

First include the App SDK JavaScript:

<script type="text/javascript" src="/apps/[version]/sdk.js"></script>

Instantiate a new TextBox:

var textbox = new rally.sdk.ui.basic.TextBox(config);

The parameters for rally.sdk.ui.basic.TextBox are as follows:

Parameter Description Example
config* A configuration object. { label: "Name", showLabel: true }
  * = required parameter

The TextBox configuration object supports the following properties:

Parameter Description
value The initial text
showLabel If showLabel is true then the label will be shown, defaults to true if label is specified, false otherwise
label The text for the description that will be placed next to the checkbox
labelPosition Where the label will be displayed, valid positions: "before", "after"
(default = "before")
rememberValue Persist the value as the default for future sessions
(default = true)
tabIndex Specify this component's place in the form field traversal order
(default = 0 )
width Specify the textbox's width in pixels, or percent if percent sign included
(default = 150)
type Specify the textbox's type: text or password
(default = "text")
  * = required parameter

Display a text box

Once created, use the display method to display the textbox:

textbox.display(domElement, onChanged);

Parameter Description Example
domElement* The element in which to display the textbox.
This may be either an element or an element ID.
"textboxSpan",
document.getElementById("textboxSpan")
onChanged A callback function that will be executed each time the value of the textbox changes. function onChanged(sender, eventArgs) {
   var textboxValue = eventArgs.value;
}
  * = required parameter

Public methods

Method Name Parameters Description Example
display See above - See above
destroy - Removes the component from the app textbox.destroy();
getValue - Returns the current text var value = textbox.getValue();
getComponentValue - Same as getValue; provides a consistent interface for retrieving the value of basic components var value =
textbox.getComponentValue();
setValue value* Sets the current text textbox.setValue("value");
setComponentValue value* Same as setValue; provides a consistent interface for setting the value of basic components textbox.setComponentValue("value");
getValidEvents - Returns an object containing the valid events for textbox var events =
textbox.getValidEvents();
  * = required parameter

Events

Events are used to notify consumers of a component when actions occur. The following methods are provided in order to interact with this component's events:

Method Parameters Description Example
addEventListener eventName*, listener*, scope Registers the specified listener with the component's queue for the specified event and returns an object which can be used to remove the event listener later. The listener parameter should be a function with two parameters: 1) the component that fired the event; 2) an eventArgs object with properties specific to the event being fired. This function will be called by the component when the event occurs. If the optional scope parameter was specified the function will be called on that object (like scope.listener(sender, args);). function listener(sender, eventArgs) {
   //Respond to event
}
var eventObj = component.addEventListener(eventName,
listener);
removeEventListener eventObj* Unregisters the specified event from the component.
The eventObj parameter should be the return value of addEventListener() when the listener was originally registered.
var eventObj =
component.addEventListener(...);
component.removeEventListener(eventObj);
getValidEvents - Returns an object with a property for each event name supported by the component. This is useful for passing as the first parameter to addEventListener(). var eventName = component.getValidEvents().onClick;

The TextBox component supports the following events:

Event Name Description Event Arguments Example
onChange Fired when the value of the textbox changes. The eventArgs object passed to any event listeners
contains the following property:
value: The value of the textbox
function onTextBoxChanged(textbox, eventArgs) {
   var value = eventArgs.value;
}
textbox.addEventListener("onChange",
   onTextBoxChanged);
onKeyDown Fired when a new character is entered in the textbox. The eventArgs object passed to any event listeners
contains the following property:
keyCode: The key code of the character entered
function onKeyDown(textbox, eventArgs) {
   var keyCode = eventArgs.keyCode;
}
textbox.addEventListener("onKeyDown",
   onKeyDown);
onKeyUp Fired when a key is released while focused in the textbox. The eventArgs object passed to any event listeners
contains the following property:
keyCode: The key code of the character entered
function onKeyUp(textbox, eventArgs) {
   var keyCode = eventArgs.keyCode;
}
textbox.addEventListener("onKeyUp",
   onKeyUp);

Example

Copy and paste the following into a CA Agile Central custom app page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- Copyright (c) 2011 CA Agile Central Software Development Corp. All rights reserved -->
<html>
<head>
<title>TextBox Example</title>
   <meta name="Name" content="Component Example: TextBox" />
   <meta name="Version" content="2012.02.26" />
   <meta name="Vendor" content="CA Agile Central Software" />
   <script type="text/javascript" src="/apps/1.26/sdk.js"></script>
   <script type="text/javascript">

     function textBoxChanged(tb, args) {
       var value = args.value;
     }

     function onLoad() {
       var config = {
         label : "Name: ",
         value : "New Story 1",
         showLabel: true
      };

       var textBox = new rally.sdk.ui.basic.TextBox(config);
        textBox.display("textbox", textBoxChanged);
      }

     rally.addOnLoad(onLoad);
   </script>
</head>
<body>
<span id="textbox"></span>
</body>
</html>

Feedback

Need more help? The CA Agile Central Community is your one-stop shop for self-service and support. To submit feedback or cases to CA Agile Central Support, find answers, and collaborate with others, please join us in the CA Agile Central Community.