-
22 Jul 2007 6:17 AM #1
Help! I have a deadline
Help! I have a deadline
I have a registration form, when a registrant chooses "no" in a yes/no combo box or a yes/no radio button, I need to require a textfield to be filled in. I have searched the forums and can't find any examples of this functionality. I would like to have the field hidden untill It is required but just required if the other field is negative is good enough.
-
22 Jul 2007 10:44 AM #2
Hi,
I am just a newbie with Ext Js. But using simple JS it could be done like this I guess:
1) add onChange action to your checkbox. Name it like myCheckAction or whatever you like
2) in that function check if checkbox is checked then Ext.get('yourHiddenInputField') and make it visible else make it hidden
3) when submiting form add validation that check if checkbox is checked then field shoud be mandatory.
I hope this helps.
-
22 Jul 2007 10:48 AM #3
add a change listener to your checkbox and connect both fields via an id attribute:
I haven't tested the code above. I have used something slightly different in my code.PHP Code:new Ext.form.Checkbox({
fieldLabel: 'Checkbox',
name: 'checkbox',
linkedField:"idOfLinkedField",
listeners:{
change:function(field, value){
var linkedField = Ext.ComponentMgr.get(field.linkedField);
linkedField.allowBlank = value===true||value=="true";
linkedField.clearInvalid();
}
}
})
...
new Ext.form.TextField({
fieldLabel: 'OptionalField',
name: 'optional',
id:"idOfLinkedField"
})
Dynamically hide or show a field is - as far as I know - not possible in Ext. But it can be easily added:
(in Ext 2.0 replace Ext.form.Form with Ext.FormPanel)PHP Code:Ext.apply(Ext.form.Form.prototype, {
renameFieldLabel:function(field, label){
if (typeof field == "string"){
field = this.findField(field);
}
var wrap = field.el.findParent(".x-form-item");
Ext.fly(wrap).child('label').update(label);
},
setFieldVisibility: function(field, visibility){
if (typeof field == "string"){
field = this.findField(field);
}
var wrap = field.el.findParent(".x-form-item");
Ext.fly(wrap).setDisplayed(visibility);
}
});
PS: a better thread title would probably attract much more people that can actually help you and not only people that want to see a post of a possibly desperate person
-
22 Jul 2007 3:05 PM #4
-
22 Jul 2007 3:23 PM #5
-
22 Jul 2007 6:44 PM #6
Don't know, IMHO that was a pretty good subject. I must have missed that topic otherwise I would have answered that.
You are right, it isn't part of any Ext component. But anything that you put in the config-object in the constructor will be applied to the object. So it's the same as writing
The call to Ext.ComponentMgr.get converts the string-id into the real Ext.form.TextField object.PHP Code:var f = new Ext.form.Checkbox({
fieldLabel: 'Checkbox',
name: 'checkbox',
listeners:{
change:function(field, value){
var linkedField = Ext.ComponentMgr.get(field.linkedField);
linkedField.allowBlank = value===true||value=="true";
linkedField.clearInvalid();
}
}
});
f.linkedField = "idOfLinkedField";
If all that linkField stuff confuses you, a normal - Web 1.0
- way would be to directly address the TextField via a variable in the change listener:
PHP Code:var c,t;
c = new Ext.form.Checkbox({
fieldLabel: 'Checkbox',
name: 'checkbox',
listeners:{
change:function(field, value){
t.allowBlank = value===true||value=="true";
t.clearInvalid();
}
}
});
...
t = new Ext.form.TextField({
fieldLabel: 'OptionalField',
name: 'optional'
}) ;
-
24 Jul 2007 3:33 PM #7
Can this work with a combo box?
Can this work with a combo box?
Can anyone show me an example of a using a combo box instead of a check box? I can't think of the proper logic to only require the text field to be required when the anser is negitive.
IE:
do you live in the usa? if the answer is no file in a textfield with the country you live in.
-
25 Jul 2007 2:36 AM #8
-
25 Jul 2007 7:38 AM #9
how can I use a combobox instead of check box
how can I use a combobox instead of check box
I am sorry I copied the wrong portion of code.
Here is the original I would like to change from using a checkbox to using a combo box.
can someone show me/lead me in the right direction on how to make the OptionalField required like in the code above using a combo box in stead of the checkbox?Code:new Ext.form.Checkbox({ fieldLabel: 'Checkbox', name: 'checkbox', linkedField:"idOfLinkedField", listeners:{ change:function(field, value){ var linkedField = Ext.ComponentMgr.get(field.linkedField); linkedField.allowBlank = value===true||value=="true"; linkedField.clearInvalid(); } } }) ... new Ext.form.TextField({ fieldLabel: 'OptionalField', name: 'optional', id:"idOfLinkedField" })
Here is my combo box
Code:new Ext.formComboBox({ fieldLabel: 'Does your organization operat in USA?', labeSeparator: '', hiddenName: 'in_usa', store: new Ext.dataSimleStor({ fields: ['id', 'yesno'], data: Ext.combodata.yes_no }), displayField: 'yesno", valueField: 'id', typeahead: true, mode: 'local', triggerAction: 'all', selectOnFocus: true, emptyText: 'Make a Selection...', width: 190, allowBlank: false, editable: false, linkedField: 'idOfLinkedField', listeners:{ change:function(field, value){ if (field.value == "1") { var linkedField = Ext.ComponentMgr.get(field.linkedField); linkedField.allowBlank = value===true||value=="true"; linkedField.clearInvalid(); } else { return; } } }), new Ext.form.TextField({ fieldLabel: 'OptionalField', name: 'optional', id:"idOfLinkedField" })Last edited by kordsmen; 25 Jul 2007 at 11:22 AM. Reason: type from Overlord
-
25 Jul 2007 8:02 AM #10


Reply With Quote
