PDA

View Full Version : Label in form



nicobarten
30 Sep 2009, 4:18 AM
Hi all,

I have a form with a fieldset. In this fieldset, normal textfields appear, but when a user logged in has not certain rights, there must be labels instead of textfields.

So i have this code:



// ... some code
layout: 'form',
defaultType: 'textfield',
border: false,
bodyStyle: 'padding: 10px 0px 0px 0px; background-color:#DFE8F6;',
width: 280, // 250 // 290
items: [
{
xtype: 'fieldset',
collapsible: false,
title: 'Persoonlijke gegevens',
autoHeight: true,
defaultType: 'textfield',
items: [
function()
{
var myTest = null;
myTest = new Ext.form.Label(
{
fieldLabel: 'Aanhef',
name: 'aanhef',
width: 128,
text: 'Dhr'
});
return myTest;
} (),
function()
{
var bla = null;
bla = new Ext.form.Label(
{
fieldLabel: 'Voorletters',
name: 'voorletters',
width: 128,
text: 'N.B.'
});
return bla;
} (),
// ... more code


So, in the function for each item, i can decide which will be shown (textfield or label) and then make the current component, and return it. With a textfield or combobox this works good, but the label's value is below the label's fieldlabel, as seen in the picture below:

http://img34.imageshack.us/img34/5783/exampletest.jpg

So what am i doing wrong? (:|

Animal
30 Sep 2009, 9:27 AM
Use a DisplayField or a TextField depending.

Animal
30 Sep 2009, 9:30 AM
That would be just



items: [{
xtype: canWrite ? 'textfield' : 'displayfield',
fieldLabel: 'Aanhef',
name: 'aanhef',
width: 128,
text: 'Dhr'
}

nicobarten
30 Sep 2009, 1:30 PM
And what if the original was a combobox instead of a textfield? (So combo or displayfield)

Because the combo has other attributes like store, etc.

Animal
30 Sep 2009, 9:39 PM
use xtype: 'combo'! 8-|

nicobarten
30 Sep 2009, 10:26 PM
err... i'm not that stupid :D

What i meant was, that a combobox uses all kind of other attributes, like store, valueField, displayField, etc. The textfield or displayField doesn't have these attributes, so i wonder how i should change the displayField to a combo with also having to add those new attributes.

Animal
30 Sep 2009, 11:13 PM
You have to configure a combo with everything it needs.

nicobarten
30 Sep 2009, 11:44 PM
ok, an example. Lets say i have the combobox as original:



items: [{
xtype: canWrite ? 'combo' : 'displayfield',
fieldLabel: 'Aanhef',
hiddenName: 'aanhef',
width: 128,
store: someStore,
valueField: 'id',
displayField: 'name'
}


If canwrite becomes false, the xtype will become displayfield. However, displayfield doesn't use
a store, valueField and displayField.

:-?

Animal
30 Sep 2009, 11:45 PM
No. It doesn't.
:-?

nicobarten
1 Oct 2009, 12:02 AM
So, if the original is the combobox with attributes like store, displayField, valueField, etc, what will happen then when the xtype changes to displayfield? The displayfield would have invalid attributes attached to it.

rblon
1 Oct 2009, 12:25 AM
did you try it?