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 var align = this.labelAlign || this.parentLabelAlign();
78 cls: 'form-group' //input-group
85 type : this.inputType,
87 autocomplete: 'new-password',
88 placeholder : this.placeholder || ''
92 input.name = this.name;
95 input.cls += ' input-' + this.size;
102 var inputblock = input;
104 if(this.hasFeedback && !this.allowBlank){
109 cls: 'glyphicon form-control-feedback'
112 if(this.removable && !this.editable && !this.tickable){
117 cls : 'has-feedback',
123 cls : 'roo-combo-removable-btn close'
133 cls : 'has-feedback',
142 if(this.removable && !this.editable && !this.tickable){
144 cls : 'roo-removable',
150 cls : 'roo-combo-removable-btn close'
157 if (this.before || this.after) {
166 cls : 'input-group-addon',
171 inputblock.cn.push(input);
173 if(this.hasFeedback && !this.allowBlank){
174 inputblock.cls += ' has-feedback';
175 inputblock.cn.push(feedback);
181 cls : 'input-group-addon',
194 cls: 'form-hidden-field'
208 cls: 'form-hidden-field'
212 cls: 'roo-select2-choices',
216 cls: 'roo-select2-search-field',
229 cls: 'roo-select2-container input-group',
234 // cls: 'typeahead typeahead-long dropdown-menu',
235 // style: 'display:none'
240 if(!this.multiple && this.showToggleBtn){
246 if (this.caret != false) {
249 cls: 'fa fa-' + this.caret
256 cls : 'input-group-addon btn dropdown-toggle',
261 cls: 'combobox-clear',
275 combobox.cls += ' roo-select2-container-multi';
278 if (align ==='left' && this.fieldLabel.length) {
280 cfg.cls += ' roo-form-group-label-left';
285 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
286 tooltip : 'This field is required'
291 cls : 'control-label',
292 html : this.fieldLabel
304 var labelCfg = cfg.cn[1];
305 var contentCfg = cfg.cn[2];
307 if(this.indicatorpos == 'right'){
312 cls : 'control-label',
316 html : this.fieldLabel
320 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
321 tooltip : 'This field is required'
334 labelCfg = cfg.cn[0];
335 contentCfg = cfg.cn[1];
338 if(this.labelWidth > 12){
339 labelCfg.style = "width: " + this.labelWidth + 'px';
342 if(this.labelWidth < 13 && this.labelmd == 0){
343 this.labelmd = this.labelWidth;
346 if(this.labellg > 0){
347 labelCfg.cls += ' col-lg-' + this.labellg;
348 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
351 if(this.labelmd > 0){
352 labelCfg.cls += ' col-md-' + this.labelmd;
353 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
356 if(this.labelsm > 0){
357 labelCfg.cls += ' col-sm-' + this.labelsm;
358 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
361 if(this.labelxs > 0){
362 labelCfg.cls += ' col-xs-' + this.labelxs;
363 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
366 } else if ( this.fieldLabel.length) {
367 // Roo.log(" label");
371 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
372 tooltip : 'This field is required'
376 //cls : 'input-group-addon',
377 html : this.fieldLabel
385 if(this.indicatorpos == 'right'){
393 html : this.fieldLabel
397 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
398 tooltip : 'This field is required'
411 // Roo.log(" no label && no align");
418 ['xs','sm','md','lg'].map(function(size){
419 if (settings[size]) {
420 cfg.cls += ' col-' + size + '-' + settings[size];
431 onResize : function(w, h){
432 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
433 // if(typeof w == 'number'){
434 // var x = w - this.trigger.getWidth();
435 // this.inputEl().setWidth(this.adjustWidth('input', x));
436 // this.trigger.setStyle('left', x+'px');
441 adjustSize : Roo.BoxComponent.prototype.adjustSize,
444 getResizeEl : function(){
445 return this.inputEl();
449 getPositionEl : function(){
450 return this.inputEl();
454 alignErrorIcon : function(){
455 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
459 initEvents : function(){
463 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
464 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
465 if(!this.multiple && this.showToggleBtn){
466 this.trigger = this.el.select('span.dropdown-toggle',true).first();
467 if(this.hideTrigger){
468 this.trigger.setDisplayed(false);
470 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
474 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
477 if(this.removable && !this.editable && !this.tickable){
478 var close = this.closeTriggerEl();
481 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
482 close.on('click', this.removeBtnClick, this, close);
486 //this.trigger.addClassOnOver('x-form-trigger-over');
487 //this.trigger.addClassOnClick('x-form-trigger-click');
490 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
494 closeTriggerEl : function()
496 var close = this.el.select('.roo-combo-removable-btn', true).first();
497 return close ? close : false;
500 removeBtnClick : function(e, h, el)
504 if(this.fireEvent("remove", this) !== false){
506 this.fireEvent("afterremove", this)
510 createList : function()
512 this.list = Roo.get(document.body).createChild({
514 cls: 'typeahead typeahead-long dropdown-menu',
515 style: 'display:none'
518 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
523 initTrigger : function(){
528 onDestroy : function(){
530 this.trigger.removeAllListeners();
531 // this.trigger.remove();
534 // this.wrap.remove();
536 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
540 onFocus : function(){
541 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
544 this.wrap.addClass('x-trigger-wrap-focus');
545 this.mimicing = true;
546 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
548 this.el.on("keydown", this.checkTab, this);
555 checkTab : function(e){
556 if(e.getKey() == e.TAB){
567 mimicBlur : function(e, t){
569 if(!this.wrap.contains(t) && this.validateBlur()){
576 triggerBlur : function(){
577 this.mimicing = false;
578 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
580 this.el.un("keydown", this.checkTab, this);
582 //this.wrap.removeClass('x-trigger-wrap-focus');
583 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
587 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
588 validateBlur : function(e, t){
593 onDisable : function(){
594 this.inputEl().dom.disabled = true;
595 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
597 // this.wrap.addClass('x-item-disabled');
602 onEnable : function(){
603 this.inputEl().dom.disabled = false;
604 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
606 // this.el.removeClass('x-item-disabled');
612 var ae = this.getActionEl();
615 ae.dom.style.display = '';
616 ae.dom.style.visibility = 'visible';
623 var ae = this.getActionEl();
624 ae.dom.style.display = 'none';
628 * The function that should handle the trigger's click event. This method does nothing by default until overridden
629 * by an implementing function.
631 * @param {EventObject} e
633 onTriggerClick : Roo.emptyFn