PDA

View Full Version : alerting for required field on screen load



bunty
30 Sep 2012, 1:55 AM
Hi all,

I have a combobox with allowBlank set to false. When the screen loads, by default the combobox does not have red color border. I want to make it red on screen load itself. Any ideas on this?


Ext.define('GradeCombo', { extend: 'Ext.form.field.ComboBox',
alias: 'widget.gradecombo',
allowBlank: false,
blankText: 'Grade is required',
queryMode: 'local',
valueField: 'id',
displayField: 'name',
});

vietits
30 Sep 2012, 2:12 AM
Try this:


Ext.define('GradeCombo', {
extend: 'Ext.form.field.ComboBox',
alias: 'widget.gradecombo',
allowBlank: false,
blankText: 'Grade is required',
queryMode: 'local',
valueField: 'id',
displayField: 'name',
listeners: {
render: function(){
this.validate();
}
}
});

bunty
30 Sep 2012, 3:05 AM
Thanks, that worked.

For some other combobox present in the screen, I want the first displayField text to be displayed in the combobox textfield when the screen loads for the first time. How to achieve that?

flanders
30 Sep 2012, 11:49 AM
It would be better to open a new thread for a new question, IMHO. Especially if the original question might provoke more reactions, things might get quite cluttered.

How about this reasoning:
- On loading of the store,
- I want to fetch the first record
- And set it as my value.

Translating that to code:




Ext.define('GradeCombo', {
extend: 'Ext.form.field.ComboBox',
alias: 'widget.gradecombo',
allowBlank: false,
blankText: 'Grade is required',
queryMode: 'local',
valueField: 'id',
displayField: 'name',
listeners: {
load: function(){
this.setValue(this.store.getAt(0));
}
}
});

mjhaston
30 Jan 2013, 8:06 AM
I have the opposite problem. All of my combobox seem to default to being marked with an error (with required field) as the message. This is when the form is first rendered before anyone types a thing. I'd like these combobox to perform like the textfields and datefields on the screen where they are marked as required when I tab through them and don't enter anything.

Strange (to me at least) ... if I click my button to form.reset() the red required messages go away. That makes me think something is going on before or when my form is rendered to try and validate it!