I have four files that look similar to these:
index.xml
<Alloy>
<Window>
<View class="container">
<View id="report">
<!-- Adds a textfield for name entry -->
<Require type="view" src="textfield" id="name"/>
<Button id="checkNameValue" title="Check Value" width="100" height="40" onClick="checkname"/>
</View>
</View>
</Window>
</Alloy>
index.js
function checkname(e) {
alert("Your name is " + $.name.getView('nameTextField').value);
}
textfield.xml
<Alloy>
<View id="nameView">
</View>
</Alloy>
textfield.js
var nameTextField = Titanium.UI.createTextField({
hintText:"Type your name",
height:40,
width:300,
top:20,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
$.nameView.add(nameTextField);
When I try clicking the Button to read the name value, I get an error:
message = "'undefined' is not an object (evaluating $.name.getView(\"nameTextField\").value')";
What is going wrong and how can I fix this?