Netarious
30 Aug 2007, 7:40 AM
I am trying to collect up to nine names including Title, FirstName, MiddleName and LastName.
The way I have implemented this is by rendering the TextFields in columns thus:
fs.column({
id: 'columnTitle',
width:60,
labelAlign: 'top'
},
new Ext.form.TextField({
fieldLabel: 'Title',
name: 'title_1',
width: 50,
tabIndex: 4
})
);
fs.column({
id: 'columnFirstName',
width:110,
labelAlign: 'top'
},
new Ext.form.TextField({
fieldLabel: 'First Name',
name: 'firstName_1',
width: 100,
tabIndex: 5
})
);
fs.column({
id: 'columnMiddleName',
width:110,
labelAlign: 'top'
},
new Ext.form.TextField({
fieldLabel: 'Middle Name',
name: 'middleName_1',
width: 100,
tabIndex: 6
})
);
fs.column({
id: 'columnLastName',
width:180,
labelAlign: 'top'
},
new Ext.form.TextField({
fieldLabel: 'Last Name',
name: 'lastName_1',
width: 150,
tabIndex: 7,
allowBlank: false
})
);
fs.column({
id: 'actionButton',
width: 20
}
);
When the user clicks the "actionButton", I am dynamically adding a new set of TextFields to the columns using this function:
function addNewClientRow()
{
if (clientIndex==9) return;
clientIndex++;
var t = new Ext.form.TextField({
name: 'title_' + clientIndex,
width: 50,
style: 'margin-bottom: 8px;',
tabIndex: clientIndex*4
});
t.render('columnTitle');
t = new Ext.form.TextField({
name: 'firstName_' + clientIndex,
width: 100,
style: 'margin-bottom: 8px;',
tabIndex: clientIndex*4+1
});
t.render('columnFirstName');
t = new Ext.form.TextField({
name: 'middleName_' + clientIndex,
width: 100,
style: 'margin-bottom: 8px;',
tabIndex: clientIndex*4+2
});
t.render('columnMiddleName');
t = new Ext.form.TextField({
name: 'lastName_' + clientIndex,
width: 150,
style: 'margin-bottom: 8px;',
tabIndex: clientIndex*4+3,
allowBlank: false
});
t.render('columnLastName');
var addClientButton = Ext.get('addNewClientButton');
if (clientIndex==9){
addClientButton.setStyle('display', 'none');
}else{
addClientButton.setStyle('margin-top', (clientIndex*31-10) + 'px');
}
}
This all works fine. However, the surname is a required field. When the first new row loses focus from the surname field, the validator highlights the field, but the alert icon doesn't appear and I get a javascript error:
"_f has no properties"
Essentially the command
var _f=this.el.findParent(".x-form-element",5,true); is not finding the required element.
Does anyone have any ideas on how I can fix this issue. From searching through the forums it seems I need to make sure the new element is a child of an element with the x-form-element class. I think its something to do with adding the control to the column but not making it a "child" as it were. Very confused!
The way I have implemented this is by rendering the TextFields in columns thus:
fs.column({
id: 'columnTitle',
width:60,
labelAlign: 'top'
},
new Ext.form.TextField({
fieldLabel: 'Title',
name: 'title_1',
width: 50,
tabIndex: 4
})
);
fs.column({
id: 'columnFirstName',
width:110,
labelAlign: 'top'
},
new Ext.form.TextField({
fieldLabel: 'First Name',
name: 'firstName_1',
width: 100,
tabIndex: 5
})
);
fs.column({
id: 'columnMiddleName',
width:110,
labelAlign: 'top'
},
new Ext.form.TextField({
fieldLabel: 'Middle Name',
name: 'middleName_1',
width: 100,
tabIndex: 6
})
);
fs.column({
id: 'columnLastName',
width:180,
labelAlign: 'top'
},
new Ext.form.TextField({
fieldLabel: 'Last Name',
name: 'lastName_1',
width: 150,
tabIndex: 7,
allowBlank: false
})
);
fs.column({
id: 'actionButton',
width: 20
}
);
When the user clicks the "actionButton", I am dynamically adding a new set of TextFields to the columns using this function:
function addNewClientRow()
{
if (clientIndex==9) return;
clientIndex++;
var t = new Ext.form.TextField({
name: 'title_' + clientIndex,
width: 50,
style: 'margin-bottom: 8px;',
tabIndex: clientIndex*4
});
t.render('columnTitle');
t = new Ext.form.TextField({
name: 'firstName_' + clientIndex,
width: 100,
style: 'margin-bottom: 8px;',
tabIndex: clientIndex*4+1
});
t.render('columnFirstName');
t = new Ext.form.TextField({
name: 'middleName_' + clientIndex,
width: 100,
style: 'margin-bottom: 8px;',
tabIndex: clientIndex*4+2
});
t.render('columnMiddleName');
t = new Ext.form.TextField({
name: 'lastName_' + clientIndex,
width: 150,
style: 'margin-bottom: 8px;',
tabIndex: clientIndex*4+3,
allowBlank: false
});
t.render('columnLastName');
var addClientButton = Ext.get('addNewClientButton');
if (clientIndex==9){
addClientButton.setStyle('display', 'none');
}else{
addClientButton.setStyle('margin-top', (clientIndex*31-10) + 'px');
}
}
This all works fine. However, the surname is a required field. When the first new row loses focus from the surname field, the validator highlights the field, but the alert icon doesn't appear and I get a javascript error:
"_f has no properties"
Essentially the command
var _f=this.el.findParent(".x-form-element",5,true); is not finding the required element.
Does anyone have any ideas on how I can fix this issue. From searching through the forums it seems I need to make sure the new element is a child of an element with the x-form-element class. I think its something to do with adding the control to the column but not making it a "child" as it were. Very confused!