manugoel2003
15 Jul 2007, 12:14 PM
Hi,
I have been working on making a search box with 3 triggers. The 1st one will be on the left of the text box and will contain a menu. The 2nd one will be to the immediate right of the text box and will act like a reset button for that search box. The 3rd one will be in the extreme right and will act like a "search" button. For further clarity please see the attachment.
978
I am facing a couple of problems.
1. As you can see in the snapshot, the 1st trigger is overlapping the text field.
2. I am not able to attach a menu to the 1st trigger. (The method I have used is wrong but it is just to highlight what I want)
Here is my code
Ext.namespace("ux");
Ext.ux.xsearch = function(config){
if (!config){return;}
};
Ext.ux.xsearch = Ext.extend(Ext.form.TriggerField, {
menu: null,
initComponent : function(){
Ext.ux.xsearch.superclass.initComponent.call(this);
this.triggerConfig = {
tag:'span', cls:'x-form-twin-triggers', cn:[
{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class},
{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger3Class}
]};
},
getTrigger : function(index){
return this.triggers[index];
},
initTrigger : function(){
var ts = this.wrap.select('.x-form-trigger', true);
this.wrap.setStyle('overflow', 'hidden');
var triggerField = this;
ts.each(function(t, all, index){
t.hide = function(){
var w = triggerField.wrap.getWidth();
this.dom.style.display = 'none';
triggerField.el.setWidth(w-triggerField.trigger.getWidth());
};
t.show = function(){
var w = triggerField.wrap.getWidth();
this.dom.style.display = '';
triggerField.el.setWidth(w-triggerField.trigger.getWidth());
};
var triggerIndex = 'Trigger'+(index+1);
if(this['hide'+triggerIndex]){
t.dom.style.display = 'none';
}
t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
t.addClassOnOver('x-form-trigger-over');
t.addClassOnClick('x-form-trigger-click');
}, this);
this.triggers = ts.elements;
},
onRender : function(ct, position){
Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
if (!Ext.isEmpty(this.menu))
{
this.menuTrigger = this.wrap.insertFirst({
tag: "img",
src: Ext.BLANK_IMAGE_URL,
cls: "x-form-trigger " + this.trigger1Class,
menu: this.menu // <------------ I was talking abt this. I want my menu here.
});
}
this.trigger = this.wrap.createChild(this.triggerConfig ||
{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
if(this.hideTrigger){
this.trigger.setDisplayed(false);
}
this.initTrigger();
if(!this.width){
var menuTriggerWidth = (this.menuTrigger) ? this.menuTrigger.getWidth() : 0;
this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth() + menuTriggerWidth);
}
},
onTrigger1Click : Ext.emptyFn,
onTrigger2Click : Ext.emptyFn,
onTrigger3Click : Ext.emptyFn
});
And my HTML code is
<input id="xs_field_01" type="text" value="manu">
<script language="JavaScript">
var mymenu = new Ext.menu.Menu({
id: 'mainMenu',
items: [
new Ext.menu.CheckItem({
text: 'I like Ext',
checked: true
}),
new Ext.menu.CheckItem({
text: 'Ext for jQuery',
checked: true
})
]
});
var trigger = new Ext.ux.xsearch({
trigger1Class: "x-form-trigger",
trigger2Class: "x-form-clear-trigger",
trigger3Class: "x-form-search-trigger",
menu: mymenu
});
trigger.onTrigger2Click = function(){
alert("trigger 1");
};
trigger.onTrigger3Click = function(){
alert("trigger 2");
};
trigger.applyTo('xs_field_01');
</script>
Can anyone help me out, I am on a very tight deadline? And btw Jack, as you must have seen, I have borrowed almost entirely from TwinTriggerField. It helped me immensely, thanx.
I have been working on making a search box with 3 triggers. The 1st one will be on the left of the text box and will contain a menu. The 2nd one will be to the immediate right of the text box and will act like a reset button for that search box. The 3rd one will be in the extreme right and will act like a "search" button. For further clarity please see the attachment.
978
I am facing a couple of problems.
1. As you can see in the snapshot, the 1st trigger is overlapping the text field.
2. I am not able to attach a menu to the 1st trigger. (The method I have used is wrong but it is just to highlight what I want)
Here is my code
Ext.namespace("ux");
Ext.ux.xsearch = function(config){
if (!config){return;}
};
Ext.ux.xsearch = Ext.extend(Ext.form.TriggerField, {
menu: null,
initComponent : function(){
Ext.ux.xsearch.superclass.initComponent.call(this);
this.triggerConfig = {
tag:'span', cls:'x-form-twin-triggers', cn:[
{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class},
{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger3Class}
]};
},
getTrigger : function(index){
return this.triggers[index];
},
initTrigger : function(){
var ts = this.wrap.select('.x-form-trigger', true);
this.wrap.setStyle('overflow', 'hidden');
var triggerField = this;
ts.each(function(t, all, index){
t.hide = function(){
var w = triggerField.wrap.getWidth();
this.dom.style.display = 'none';
triggerField.el.setWidth(w-triggerField.trigger.getWidth());
};
t.show = function(){
var w = triggerField.wrap.getWidth();
this.dom.style.display = '';
triggerField.el.setWidth(w-triggerField.trigger.getWidth());
};
var triggerIndex = 'Trigger'+(index+1);
if(this['hide'+triggerIndex]){
t.dom.style.display = 'none';
}
t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
t.addClassOnOver('x-form-trigger-over');
t.addClassOnClick('x-form-trigger-click');
}, this);
this.triggers = ts.elements;
},
onRender : function(ct, position){
Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
if (!Ext.isEmpty(this.menu))
{
this.menuTrigger = this.wrap.insertFirst({
tag: "img",
src: Ext.BLANK_IMAGE_URL,
cls: "x-form-trigger " + this.trigger1Class,
menu: this.menu // <------------ I was talking abt this. I want my menu here.
});
}
this.trigger = this.wrap.createChild(this.triggerConfig ||
{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
if(this.hideTrigger){
this.trigger.setDisplayed(false);
}
this.initTrigger();
if(!this.width){
var menuTriggerWidth = (this.menuTrigger) ? this.menuTrigger.getWidth() : 0;
this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth() + menuTriggerWidth);
}
},
onTrigger1Click : Ext.emptyFn,
onTrigger2Click : Ext.emptyFn,
onTrigger3Click : Ext.emptyFn
});
And my HTML code is
<input id="xs_field_01" type="text" value="manu">
<script language="JavaScript">
var mymenu = new Ext.menu.Menu({
id: 'mainMenu',
items: [
new Ext.menu.CheckItem({
text: 'I like Ext',
checked: true
}),
new Ext.menu.CheckItem({
text: 'Ext for jQuery',
checked: true
})
]
});
var trigger = new Ext.ux.xsearch({
trigger1Class: "x-form-trigger",
trigger2Class: "x-form-clear-trigger",
trigger3Class: "x-form-search-trigger",
menu: mymenu
});
trigger.onTrigger2Click = function(){
alert("trigger 1");
};
trigger.onTrigger3Click = function(){
alert("trigger 2");
};
trigger.applyTo('xs_field_01');
</script>
Can anyone help me out, I am on a very tight deadline? And btw Jack, as you must have seen, I have borrowed almost entirely from TwinTriggerField. It helped me immensely, thanx.