Initialize the textfields in Sencha touch 2 - sencha-touch-2

I have a sencha touch form, which has two textfields. I want to assign some text to them on page load. I tried setting values in init and launch functions. But in those function textfield are not available, they are undefined. So which event should be used for this purpose?

Either set the values with the setRecord({textFieldName1: "value", textFieldName2: "value"}) method of the container, or assign an id to the text fields and access them via Ext.getCmp('textFieldName').setValue("value") in the initializemethod of the container.

Can't you use the value property directly ? Setting the value will make the textfield fill with the corresponding value of value property i.e in our case, "Sample Text 1" etc ..
e.g
{
xtype:'textfield,
value:'Sample Text 1 ',
},
{
xtype:'textfield,
value:'Sample Text 2 ',
}

Related

Sencha Touch 2.0 Multiple List Item Buttons

Does anyone know if it is possible to have multiple icon buttons on a Sencha Touch list item that listen to different events? If so, how can I accomplish this?
For instance, say I have a list of people and there's an icon for email, phone and a map to their location for each person. I want to show 3 small icons and be able to map each icon to do 3 separate actions.
This depends on how you are creating your buttons.
If the buttons are simple HTML using itemTpl, you can just listen to the itemtap event on List and use the event argument to detect which button you pressed. You could do this via a custom attribute or even a className:
myListItemTapListener: function(list, index, target, e) {
var el = Ext.get(e.getTarget());
if (el.hasClass('map')) {
this.navigate(index);
} else if(el.hasClass('email')) {
this.email(index);
} else if(el.hasClass('phone')) {
this.phone(index);
}
}
If your buttons are actual Ext.Button's inside a component List, you can simply add a listener onto each button when you create the component. There is an example of how to do this in the DataView Guide in the Sencha Docs.
Component DataView may help you. You can see this [guide]: http://docs.sencha.com/touch/2-0/#!/guide/dataview-section-4
I have wrote a [demo]: https://github.com/hs3180/Sencha-Touch-Component-DataView
, in app/view/,
Main.js, a dataview component with useComponets true, and set defaultType to 'demo.view.Item'.
Item.js, a DataItem, the visible content of each item is a panel ( in Card.js ). I use datamap to link name in record ( within store ) to userName ( in demo.view.Card ).
Card.js, a Panel for each person. A user name title and 3 buttons.

NSPredicateEditor is clearing the value of its NSTextField

I'm using NSPredicateEditor in my project. One of my rows has 2 popup buttons and a text field on the right. If I have something typed in the text field, when I select a different menu item from either of the popup buttons then the text in the text field is deleted. That seems to be the default behavior and I don't want that text deleted. I've tried everything I can think of and can't seem to handle this. Any ideas how to change this behavior?
You could save the data by using NSUserDefault it will save and load the data (It won't delete your data unless the user does).
Access the text fields via the row template's templateViews property.
This allows you to get the custom values that have been entered into the textfield. Save the value when it changes.
class YourCustomRowTemplate : NSPredicateEditorRowTemplate {
func printTextFieldValues() {
let templateViews = super.templateViews
for view in templateViews {
if let textField = view as? NSTextField {
let text = textField.stringValue
print("Text in the texfield is: \(text)")
}
}
}
}
You can set the values the same way, by subclassing NSPredicateEditorRowTemplate and overriding the templateViews method.

extjs 4.1.0 how to get textfield values without using their id

I have one Textfield, Combo and a Radio. I want to get values of these 3 fields on clicking one button. How I can get the values of above 3 without using Ext.getCmp('id').getValue();
Is there any other method is their to get the values,
please let me know.
It depends on how you have contained your fields and the button you want to click to get their values.
You can navigate up and down your containers
var TheComponent = this.up('form').down('#MyTextField')
This climbs up your container hierarchy until it finds a 'form' container (doesn't matter what its Id or name is) and them climbs down until it finds a component with the id: 'MyTextField'
If your radio button is in a radio button group container you can retrieve an object that has all your 'on' key/values.
If your container is a form you can use the method proposed by lzhaki and retrieve an object that contains all the values on your form. Just remember that combo boxes behave differently to text boxes.
Each of these methods will return either a single value or an object containing a group of values.
In ExtJS 4.1, I found the prior example was close, but incorrect:
var TheComponent = this.up('form').down('#MyTextField')
There is no "down" method in the form object (apparently form fields aren't included in the down method's navigation logic).
Here's what worked for me to set initial focus on an edit field within a form.
var theForm = this.down('form').getForm();
var theField = theForm.findField('idEditVolname');
theField.focus();
You still must use getForm() to get the embedded form object, followed by findField() to locate the specific field - at least that's what works for me.
I don't know if this is still relevant, but here goes.
First of all, in Extjs4 and up, you use Ext.ComponentQuery.query() instead of Ext.getCmp().
What this allows you to do is access any xtype you have directly, just like the up, and down methods mentioned in other answers, but this method doesn't need any anchors as it searches the entire component hierarchy. Since you have only one of each element on the page that would be very easy to achieve without using id's.
I would name the main panel that contains the fields, but that's just for convenience.
Look at this fiddle
The code is really simple:
var panel = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
name: 'myForm',
title: 'Sample Test',
layout: 'anchor',
height: 200,
items: [{
xtype:'textfield',
fieldLabel: 'text',
value: 'Oh yeah!'
}]
});
var myVal = Ext.ComponentQuery.query('panel[name=myForm] textfield')[0];
alert (myVal.getValue());
The same can be done with the radio and combo fields, and you don't need a form for that, though it is more logical that way.

Dojo OnKeyPress Handler: TextBox value is blank

I have a Dojo form that does not contain a submit button. Instead, I added an onkeypress handler to calls a method when Enter is pressed. The problem I am having is that when I hit enter before blurring off the current field, the _process method thinks that field is empty.
Or in other words: type in field1. hit tab. type in field2. hit enter. field2 is blank unless i click off the field or shift-tab back.
Any ideas?
dojo.connect(dijit.byId("fkrform"),"onKeyPress",function(e) {
if (e.keyCode == dojo.keys.ENTER) {
_process();
}
and the method it calls:
function _process()
{
var field1 = dijit.byId("field1").value;
var field2 = dijit.byId("field2").value;
alert(username);
alert(password);
...do stuff...
}
The fields are of dojoType: dijit.form.TextBox, and the form is: dijit.form.Form
Use dijit.byId('field1').get('value') instead of directly try to access the property "value". In your example you saved the value in the variable field1 and field2 and in the alert you use the variable username and password could be the answer why you don't get anything. But you still should use the get method to get a property instead of directly access the property.
When you press "Enter" your form will submit. So you need to connect to the "onSubmit" event on the form, instead of onkeyPress or onKeyUp.
The first example i created prints the value of the input box on every key someone pressed in the console.
http://jsfiddle.net/a8FHg/
But what you really wanted was hooking into the submit. I modified the example. The new example connects to "onSubmit" and creates an alert box with the text of the user input.
http://jsfiddle.net/a8FHg/1/
For completness if jsfiddle doesn't work some day. You JavaScript should looks like this.
dojo.ready(function(){
var form = dijit.byId('form');
var box = dijit.byId('box');
var submit = function(event) {
dojo.stopEvent(event);
alert("User input was " + box.get('value'));
};
dojo.connect(form, 'onSubmit', submit);
});
Assuming your form in your HTML has the id form and your box have the id box.

Accessing a variable in nested movie clips - Actionscript 2

I would like to access a variable(txt1) set on an input box.
The input box is in a movie clip called txt_0143. am trying to
access it in the parent movie clip called part_0.010 . So the
hierarchy goes as root->part_0.010->txt_0143->txt1.
I have used the following function on another sibling clip in part_0.010:
on (release) {
getURL("http://www.google.com/?q=" + txt1, "_blank");
}
When I just use the txt1 in the script from part_0.010, i get
_level0.instance28.rm.txt1 in the place where the text should be.
Else i tried _root.txt_0143.txt1, gives me undefined.
To get the text of a TextField, you need to use the text property.
So when you output the txt1 it just gives your the path to that object. So it seems that you have the right object if it returns "_level0.instance28.rm.txt1" instead of the actual text.
So your code should look like this instead:
on (release) {
getURL("http://www.google.com/?q=" + txt1.text, "_blank");
}