4 * trigger field - base class for combo..
9 * @class Roo.bootstrap.TriggerField
10 * @extends Roo.bootstrap.Input
11 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
12 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
13 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
14 * for which you can provide a custom implementation. For example:
16 var trigger = new Roo.bootstrap.TriggerField();
17 trigger.onTriggerClick = myTriggerFn;
18 trigger.applyTo('my-field');
21 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
22 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
23 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
24 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
25 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
28 * Create a new TriggerField.
29 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
30 * to the base TextField)
32 Roo.bootstrap.TriggerField = function(config){
33 this.mimicing = false;
34 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
37 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
39 * @cfg {String} triggerClass A CSS class to apply to the trigger
42 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
47 * @cfg {Boolean} removable (true|false) special filter default false
51 /** @cfg {Boolean} grow @hide */
52 /** @cfg {Number} growMin @hide */
53 /** @cfg {Number} growMax @hide */
59 autoSize: Roo.emptyFn,
71 getAutoCreate : function(){
73 Roo.log('testingggggg');
75 var align = this.labelAlign || this.parentLabelAlign();
80 cls: 'form-group' //input-group
87 type : this.inputType,
89 autocomplete: 'new-password',
90 placeholder : this.placeholder || ''
94 input.name = this.name;
97 input.cls += ' input-' + this.size;
104 var inputblock = input;
106 if(this.hasFeedback && !this.allowBlank){
110 cls: 'glyphicon form-control-feedback'
113 if(this.removable && !this.editable && !this.tickable){
115 cls : 'has-feedback',
121 cls : 'roo-combo-removable-btn close'
128 cls : 'has-feedback',
137 if(this.removable && !this.editable && !this.tickable){
139 cls : 'roo-removable',
145 cls : 'roo-combo-removable-btn close'
152 if (this.before || this.after) {
161 cls : 'input-group-addon',
166 inputblock.cn.push(input);
168 if(this.hasFeedback && !this.allowBlank){
169 inputblock.cls += ' has-feedback';
170 inputblock.cn.push(feedback);
176 cls : 'input-group-addon',
189 cls: 'form-hidden-field'
203 cls: 'form-hidden-field'
207 cls: 'roo-select2-choices',
211 cls: 'roo-select2-search-field',
224 cls: 'roo-select2-container input-group',
229 // cls: 'typeahead typeahead-long dropdown-menu',
230 // style: 'display:none'
235 if(!this.multiple && this.showToggleBtn){
241 if (this.caret != false) {
244 cls: 'fa fa-' + this.caret
251 cls : 'input-group-addon btn dropdown-toggle',
256 cls: 'combobox-clear',
270 combobox.cls += ' roo-select2-container-multi';
273 if (align ==='left' && this.fieldLabel.length) {
275 cfg.cls += ' roo-form-group-label-left';
280 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
281 tooltip : 'This field is required'
286 cls : 'control-label',
287 html : this.fieldLabel
299 var labelCfg = cfg.cn[1];
300 var contentCfg = cfg.cn[2];
302 if(this.indicatorpos == 'right'){
307 cls : 'control-label',
311 html : this.fieldLabel
315 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
316 tooltip : 'This field is required'
329 labelCfg = cfg.cn[0];
330 contentCfg = cfg.cn[1];
333 if(this.labelWidth > 12){
334 labelCfg.style = "width: " + this.labelWidth + 'px';
337 if(this.labelWidth < 13 && this.labelmd == 0){
338 this.labelmd = this.labelWidth;
341 if(this.labellg > 0){
342 labelCfg.cls += ' col-lg-' + this.labellg;
343 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
346 if(this.labelmd > 0){
347 labelCfg.cls += ' col-md-' + this.labelmd;
348 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
351 if(this.labelsm > 0){
352 labelCfg.cls += ' col-sm-' + this.labelsm;
353 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
356 if(this.labelxs > 0){
357 labelCfg.cls += ' col-xs-' + this.labelxs;
358 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
361 } else if ( this.fieldLabel.length) {
362 // Roo.log(" label");
366 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
367 tooltip : 'This field is required'
371 //cls : 'input-group-addon',
372 html : this.fieldLabel
380 if(this.indicatorpos == 'right'){
388 html : this.fieldLabel
392 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
393 tooltip : 'This field is required'
406 // Roo.log(" no label && no align");
413 ['xs','sm','md','lg'].map(function(size){
414 if (settings[size]) {
415 cfg.cls += ' col-' + size + '-' + settings[size];
426 onResize : function(w, h){
427 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
428 // if(typeof w == 'number'){
429 // var x = w - this.trigger.getWidth();
430 // this.inputEl().setWidth(this.adjustWidth('input', x));
431 // this.trigger.setStyle('left', x+'px');
436 adjustSize : Roo.BoxComponent.prototype.adjustSize,
439 getResizeEl : function(){
440 return this.inputEl();
444 getPositionEl : function(){
445 return this.inputEl();
449 alignErrorIcon : function(){
450 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
454 initEvents : function(){
458 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
459 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
460 if(!this.multiple && this.showToggleBtn){
461 this.trigger = this.el.select('span.dropdown-toggle',true).first();
462 if(this.hideTrigger){
463 this.trigger.setDisplayed(false);
465 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
469 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
472 if(this.removable && !this.editable && !this.tickable){
473 var close = this.closeTriggerEl();
476 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
477 close.on('click', this.removeBtnClick, this, close);
481 //this.trigger.addClassOnOver('x-form-trigger-over');
482 //this.trigger.addClassOnClick('x-form-trigger-click');
485 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
489 closeTriggerEl : function()
491 var close = this.el.select('.roo-combo-removable-btn', true).first();
492 return close ? close : false;
495 removeBtnClick : function(e, h, el)
499 if(this.fireEvent("remove", this) !== false){
501 this.fireEvent("afterremove", this)
505 createList : function()
507 this.list = Roo.get(document.body).createChild({
509 cls: 'typeahead typeahead-long dropdown-menu',
510 style: 'display:none'
513 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
518 initTrigger : function(){
523 onDestroy : function(){
525 this.trigger.removeAllListeners();
526 // this.trigger.remove();
529 // this.wrap.remove();
531 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
535 onFocus : function(){
536 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
539 this.wrap.addClass('x-trigger-wrap-focus');
540 this.mimicing = true;
541 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
543 this.el.on("keydown", this.checkTab, this);
550 checkTab : function(e){
551 if(e.getKey() == e.TAB){
562 mimicBlur : function(e, t){
564 if(!this.wrap.contains(t) && this.validateBlur()){
571 triggerBlur : function(){
572 this.mimicing = false;
573 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
575 this.el.un("keydown", this.checkTab, this);
577 //this.wrap.removeClass('x-trigger-wrap-focus');
578 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
582 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
583 validateBlur : function(e, t){
588 onDisable : function(){
589 this.inputEl().dom.disabled = true;
590 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
592 // this.wrap.addClass('x-item-disabled');
597 onEnable : function(){
598 this.inputEl().dom.disabled = false;
599 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
601 // this.el.removeClass('x-item-disabled');
607 var ae = this.getActionEl();
610 ae.dom.style.display = '';
611 ae.dom.style.visibility = 'visible';
618 var ae = this.getActionEl();
619 ae.dom.style.display = 'none';
623 * The function that should handle the trigger's click event. This method does nothing by default until overridden
624 * by an implementing function.
626 * @param {EventObject} e
628 onTriggerClick : Roo.emptyFn