Error when set "disabled" config to customized Ext.field.Text - sencha-touch-2

I have a customized text box which gives me a textbox with a button in textfield next to it.
(run the code you'll see what I mean).
The only problem is that if I set the disabled state to false I get an error saying:
Uncaught TypeError: Object [object Object] has no method 'getValue'
But if I set it to true all is good.
This is my code:
var disabled = false;
var _oInput = Ext.create("Ext.field.Text", {
flex: 8,
labelWidth:0,
labelAlign: "right",
value: self.psValue,
});
var _oSenchaObject = Ext.create("Ext.field.Text",{
label: "test",
disabled: disabled, //This gives me the error
component: {
xtype: 'container',
layout: 'hbox',
items: [
_oInput,
{
xtype: 'button',
flex: 1,
text: '...',
//disabled: disabled,
}
]
},
});
var formPanelComment = Ext.create('Ext.form.Panel', {
title:"Comments",
items: [{
xtype: 'fieldset',
title: "Comments",
items: [
_oSenchaObject
]
}]
});

Good question. :)
This is because of a conflict when you've defined your "custom" textfield (containing a normal textfield with an inner button).
Have a look at your code snippet, the line which gives you an error is:
var _oSenchaObject = Ext.create("Ext.field.Text",{
...
disabled: disabled, //This gives me the error
component: {
...
},
});
Here, disabled config is applied to children components (which are defined in component config), but Sencha Touch does not know how to correctly disable your textfield, disable your inner container (which contains another field and button). I guess it's something like a bug, or framework limitation.
So, the solution is just set disabled config to each of your single children. In the example above, just move that line to _oInput's config.
Hope it helps.

Related

Sencha Touch, how to pass data from list to form?

I`m trying to write editable list with sencha touch,
I saw many examples but nothing did not work properly so I decided to build from scratch,
I have a list with items and on item tap my controller run the next code
showDetail: function (list, record) {
this.getMain().push({
xtype: 'vedit',
title: record.fullDetails(),
data: record.getData()
});
My "vEdit" screen is an form that should display the current tapped item data
This is the code for the edit form:
var form = Ext.define('TM.view.vEdit', {
extend: 'Ext.form.Panel',
xtype: 'vedit',
config: {
title: 'Edit task',
styleHtmlContent: true,
scrollable: 'vertical',
items: [
{
xtype: 'textfield',
name: 'title',
label: ''
},
{
xtype: 'textfield',
name: 'desc',
label: ''
}
]
}
});
I tried to load the data with the next code:
var ed = Ext.create('TM.model.mTasks', {
title: 'Ed',
desc: 'ed#sencha.com'
});
form.setRecord(ed);
and getting the next error:
Uncaught TypeError: Object function () {
return this.constructor.apply(this, arguments);
} has no method 'setRecord'
NEED YOUR HELP,
Thanks!
Since you have not define a field named record in form's config, so you won't get setRecord() method.
To pass on data you may try doing this:
form.config.record = ed;
and in initialize function of view you can get it like:
var taskData = this.config.record;
var form = Ext.define('TM.view.vEdit', {
Man, you need to create new form(), because it's just a type definition.

getting error when calling the function using sencha touch [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
how to get the form values and insert that values in the db using sencha touch
im new to sencha touch.I want to create a form and submit that form details in the database .for this one i write the following code.
Ext.define("Form.view.Main",{
extend: "Ext.form.Panel",
requires:['Ext.Button',
'Ext.Spacer',
'Ext.field.Password'
],
config: {
fullscreen: true,
id:'form',
items: [
{
xtype:'fieldset',
items:[
{
xtype: 'textfield',
name : 'name',
label: 'Name'
},
{
xtype: 'emailfield',
name : 'email',
label: 'Email',
placeHolder: 'Email address',
useClearIcon: true
},
{
xtype: 'passwordfield',
name : 'password',
label: 'Password',
allowBlank:'false'
}
]
},
{
centered:'true',
xtype:'button',
id:'submitBtn',
text:'Submit',
ui:'confirm',
width:100,
listeners: {
tap : function(thisTxt,eventObj){
var form = Ext.getCmp('form');
var values = thisTxt.getValues();
alert(values.name);
Ext.Ajax.request({
url:'http://localhost/sencha2011/form/insert.php',
params:values,
success : function(response){
var text = response.responseText;
Ext.Msg.alert('Success', text);
},
failure : function(response){
Ext.Msg.alert('Error','Error while submitting the form');
console.log(response.responseText);
}
});
}
}
}
]
}
});
when i try to execute this app ,executed(debug) successfully.when i open the application in the browser ,i have the error as " Uncaught TypeError: Cannot call method 'getValues' of undefined " in console window,and form only displayed .when i click the submit button nothing happens.can any one help to solve this one.
thanks in advance...
Firstly, you put id of your form at the wrong place, it should be placed outside of the items config
config: {
fullscreen: true,
id: 'form'
items: [
...........
}
Secondly, your query is wrong, change this query:
var form = Ext.getCmp(form);
to this:
var form = Ext.getCmp('form');
Finally, since getvalues will return you an object containing the value of each field in the form so if you want to access, for instance, your name field, just do like this:
alert(values.name);
Hope it helps :)
Instead of
var values = thisTxt.getValues();
try
var values = form.getValues();
or
var values = this.parent.getValues();
because thisTxt is the button not the form, and getValues() should be called on form panel.

Hide searchfield in detailCard

I did a search on the elements of the list, but the problem is that the search field is displayed on a detailed card of the list item.I need to hide search field in detailed card.
I tried to hide it in controller:
showDetail: function(list, record) {
this.getMain().push({
xtype: 'recipedetail',
title: record.fullName(),
data: record.data
}),
this.getMain().getNavigationBar.hide({
xtype: 'searchfield',
itemId:'contact_search'
})
}
And tried to hide it in detail card:
config: {
...,
items: [{
xtype: 'searchfield',
itemId:'contact_search',
hidden: true
}]
}
But searchfield still displayed. Errors in code or in the direction of my thoughts?
http://www.senchafiddle.com/#4hKD8#uZlr7#JywGI#3D6PK#DOaF9#oVfK0#jdzF3
There is quite a lot of error in your code to hide the searchbar.
You for the () at the getNavigationbar function
The hide function takes an animation or a boolean as a parameter, not the component your want to hide
You forgot the semi-colon
Now, to hide the searchfield, first add a reference to this searchfield in the config of your controller :
config: {
refs: {
main: 'mainpanel',
searchfield: 'mainpanel searchfield'
},
...
Now you can access your searchfield component with this.getSearchfield(), so you just need to do :
this.getSearchfield().hide();
Hope this helps

ExtJS: Why isn't autosize working for my textfields?

I have a FormPanel (Ext.form.Panel) with text fields; I'd like the text fields to automatically resize so that their entire contents are visible, but the following isn't working:
Ext.define('myapp.view.admin.EditUserFormPanel', {
extend: 'Ext.form.Panel',
initComponent: function() {
var me = this;
me.items = [
{
xtype: 'textfield',
fieldLabel: 'OpenID',
name: 'openid',
grow: true,
listeners: {
autosize: function(newWidth) {
console.log(newWidth);
},
focus: function(txtField) {
console.log('focus fired');
txtField.autoSize();
}
}
}
];
me.callParent();
}
});
Both of my event handlers fire. However, autosize only fires when the form is rendered; not when I try to manually call autoSize().
Any ideas?
Changing the layout to something other than the default 'anchor' solved the problem. Example:
I have a working example that anyone can try running if it's helpful: http://jsfiddle.net/clint_harris/5wzjG/

Sencha : can't call method "update" of undefined

Here, i'm registering my app:
App = new Ext.Application({
name: "App",
launch: function() {
this.views.viewport = new this.views.Viewport();
}
});
This is the way i register new panels and components. I put each of them into seperate js files.
App.views.Viewport = Ext.extend(Ext.TabPanel, {
fullscreen: true,
tabBar: {
dock: 'bottom',
layout: {
pack: 'center'
}
},
items: [
{
xtype: 'cPanel'
},
{
xtype: 'anotherPanel'
}
]
});
// register this new extended type
Ext.reg('App.views.viewport', App.views.Viewport);
I added the other components in the same manner.
In one my components which is a list view, I want to change the container panel's activeItem with another panel when tappen on an item, like this: ( Viewport contains this container panel)
App.views.ListApp = Ext.extend(Ext.List, {
store: App.store,
itemTpl: "...",
onItemDisclosure: function(record) {
App.detailPanel.update(record.data);
App.cPanel.setActiveItem("detailPanel");
},
listeners: {
itemtap: function(view, index, item, e) {
var rec = view.getStore().getAt(index);
App.views.detailPanel.update(rec.data);
App.views.cPanel.setActiveItem("detailPanel", {type:"slide", direction: "left"});
}
}
});
App.views.detailPanel.update(rec.data);
But it says: can't call method "update" of undefined
I tried different variations on that line, like:
App.detailPanel.update(rec.data);
and i tried to give detailPanel and cPanel ids, where they were added to their container panel, and tried to reach them with Ext.get(), but none of these worked.
What is the problem here?
And any other advices would be appreciated.
Thanks.
The lazy way: give the panels ids and use:
Ext.getCmp(id)
The recommended way: Assign itemId to your panel and use:
App.views.viewport.getComponent(itemId)
This will allow you to have more than one instance of the same component at aby given time, the first example is not valid cause you can only have a singular id in the DOM tree.
Also getComponent only works for components stored in the items collection.