-
15 Oct 2012 12:57 PM #1
Answered: Why doesn't Sencha Touch 2 have an xtype displayfield?
Answered: Why doesn't Sencha Touch 2 have an xtype displayfield?
If you look in Ext documentation there is an xtype displayfield, but not in Sencha Touch. Is there is a replacement for displayfield in Sencha Touch2?
-
Best Answer Posted by mitchellsimoens
Having a container is valid, no reason to always need to use a form field within a form.
-
15 Oct 2012 1:26 PM #2
-
15 Oct 2012 1:32 PM #3
I am inside a form panel and all my form fields are wrapped in a fieldset. I was hoping to use a form field. I believe the displayfield in Ext is just text in a div. I would like to do something similar.
-
17 Oct 2012 5:24 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
- Answers
- 3113
Having a container is valid, no reason to always need to use a form field within a form.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
17 Oct 2012 6:36 AM #5
Easy to write your own. Add a little CSS and you're done.
Code:Ext.define('My.view.DisplayField', { extend: 'Ext.field.Field', xtype: 'displayField', config: { displayText: null, component: { xtype: 'displayFieldComponent' } }, initialize: function() { var me = this, comp = me.getComponent(); me.callParent(); }, updateDisplayText: function(value) { var me = this, comp = me.getComponent(); comp.displayElement.setHtml(value); } }); Ext.define('My.view.DisplayFieldComponent', { extend: 'Ext.Component', xtype: 'displayFieldComponent', config: { cls: 'x-field-input' }, getTemplate: function() { return [{ reference: 'displayElement', tag: 'div' }] } }); Ext.create('Ext.form.Panel', { fullscreen: true, items: [ { xtype: 'fieldset', title: 'Enter your name', items: [ { xtype: 'textfield', label: 'First Name', name: 'firstName' }, { xtype: 'textfield', label: 'Last Name', name: 'lastName' }, { xtype: 'displayField', label: 'Display Only', displayText: 'Can\'t touch this' } ] } ] });
-
17 Oct 2012 6:41 AM #6
-
17 Oct 2012 9:22 AM #7
I tried writing my own, but I get the Cannot create an instance of unrecognized alias: widget.displayFieldComponent ​error.
-
17 Oct 2012 9:27 AM #8
Did you include both classes?
-
25 Oct 2012 12:08 PM #9
I included 'MyApp.view.DisplayField'. What other class are you referring to?
-
19 Feb 2013 2:05 PM #10
Thanks "estesbubba" for your code. Here's my slightly improved version:
The main change is "setValue", for allowing the field to behave like just another field when loading data into the form.Code:Ext.define('My.view.DisplayField', { extend: 'Ext.field.Field', xtype: 'displayField', config: {component: {xtype: 'displayFieldComponent'}}, setValue: function(value) {this.getComponent().displayElement.setHtml(value);return this;} }); Ext.define('My.view.DisplayFieldComponent', { extend: 'Ext.Component', xtype: 'displayFieldComponent', config: {cls: 'x-field-input'}, getTemplate: function() {return [{reference: 'displayElement', tag: 'div', style: 'padding:10px'}]} });


Reply With Quote