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){
108 cls: 'glyphicon form-control-feedback'
111 if(this.removable && !this.editable && !this.tickable){
113 cls : 'has-feedback',
119 cls : 'roo-combo-removable-btn close'
126 cls : 'has-feedback',
135 if(this.removable && !this.editable && !this.tickable){
137 cls : 'roo-removable',
143 cls : 'roo-combo-removable-btn close'
150 if (this.before || this.after) {
159 cls : 'input-group-addon',
164 inputblock.cn.push(input);
166 if(this.hasFeedback && !this.allowBlank){
167 inputblock.cls += ' has-feedback';
168 inputblock.cn.push(feedback);
174 cls : 'input-group-addon',
187 cls: 'form-hidden-field'
201 cls: 'form-hidden-field'
205 cls: 'roo-select2-choices',
209 cls: 'roo-select2-search-field',
222 cls: 'roo-select2-container input-group',
227 // cls: 'typeahead typeahead-long dropdown-menu',
228 // style: 'display:none'
233 if(!this.multiple && this.showToggleBtn){
239 if (this.caret != false) {
242 cls: 'fa fa-' + this.caret
249 cls : 'input-group-addon btn dropdown-toggle',
254 cls: 'combobox-clear',
268 combobox.cls += ' roo-select2-container-multi';
271 if (align ==='left' && this.fieldLabel.length) {
273 cfg.cls += ' roo-form-group-label-left';
278 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
279 tooltip : 'This field is required'
284 cls : 'control-label',
285 html : this.fieldLabel
297 var labelCfg = cfg.cn[1];
298 var contentCfg = cfg.cn[2];
300 if(this.indicatorpos == 'right'){
305 cls : 'control-label',
309 html : this.fieldLabel
313 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
314 tooltip : 'This field is required'
327 labelCfg = cfg.cn[0];
328 contentCfg = cfg.cn[1];
331 if(this.labelWidth > 12){
332 labelCfg.style = "width: " + this.labelWidth + 'px';
335 if(this.labelWidth < 13 && this.labelmd == 0){
336 this.labelmd = this.labelWidth;
339 if(this.labellg > 0){
340 labelCfg.cls += ' col-lg-' + this.labellg;
341 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
344 if(this.labelmd > 0){
345 labelCfg.cls += ' col-md-' + this.labelmd;
346 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
349 if(this.labelsm > 0){
350 labelCfg.cls += ' col-sm-' + this.labelsm;
351 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
354 if(this.labelxs > 0){
355 labelCfg.cls += ' col-xs-' + this.labelxs;
356 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
359 } else if ( this.fieldLabel.length) {
360 // Roo.log(" label");
364 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
365 tooltip : 'This field is required'
369 //cls : 'input-group-addon',
370 html : this.fieldLabel
378 if(this.indicatorpos == 'right'){
386 html : this.fieldLabel
390 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
391 tooltip : 'This field is required'
404 // Roo.log(" no label && no align");
411 ['xs','sm','md','lg'].map(function(size){
412 if (settings[size]) {
413 cfg.cls += ' col-' + size + '-' + settings[size];
424 onResize : function(w, h){
425 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
426 // if(typeof w == 'number'){
427 // var x = w - this.trigger.getWidth();
428 // this.inputEl().setWidth(this.adjustWidth('input', x));
429 // this.trigger.setStyle('left', x+'px');
434 adjustSize : Roo.BoxComponent.prototype.adjustSize,
437 getResizeEl : function(){
438 return this.inputEl();
442 getPositionEl : function(){
443 return this.inputEl();
447 alignErrorIcon : function(){
448 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
452 initEvents : function(){
456 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
457 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
458 if(!this.multiple && this.showToggleBtn){
459 this.trigger = this.el.select('span.dropdown-toggle',true).first();
460 if(this.hideTrigger){
461 this.trigger.setDisplayed(false);
463 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
467 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
470 if(this.removable && !this.editable && !this.tickable){
471 var close = this.closeTriggerEl();
474 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
475 close.on('click', this.removeBtnClick, this, close);
479 //this.trigger.addClassOnOver('x-form-trigger-over');
480 //this.trigger.addClassOnClick('x-form-trigger-click');
483 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
487 closeTriggerEl : function()
489 var close = this.el.select('.roo-combo-removable-btn', true).first();
490 return close ? close : false;
493 removeBtnClick : function(e, h, el)
497 if(this.fireEvent("remove", this) !== false){
499 this.fireEvent("afterremove", this)
503 createList : function()
505 this.list = Roo.get(document.body).createChild({
507 cls: 'typeahead typeahead-long dropdown-menu',
508 style: 'display:none'
511 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
516 initTrigger : function(){
521 onDestroy : function(){
523 this.trigger.removeAllListeners();
524 // this.trigger.remove();
527 // this.wrap.remove();
529 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
533 onFocus : function(){
534 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
537 this.wrap.addClass('x-trigger-wrap-focus');
538 this.mimicing = true;
539 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
541 this.el.on("keydown", this.checkTab, this);
548 checkTab : function(e){
549 if(e.getKey() == e.TAB){
560 mimicBlur : function(e, t){
562 if(!this.wrap.contains(t) && this.validateBlur()){
569 triggerBlur : function(){
570 this.mimicing = false;
571 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
573 this.el.un("keydown", this.checkTab, this);
575 //this.wrap.removeClass('x-trigger-wrap-focus');
576 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
580 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
581 validateBlur : function(e, t){
586 onDisable : function(){
587 this.inputEl().dom.disabled = true;
588 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
590 // this.wrap.addClass('x-item-disabled');
595 onEnable : function(){
596 this.inputEl().dom.disabled = false;
597 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
599 // this.el.removeClass('x-item-disabled');
605 var ae = this.getActionEl();
608 ae.dom.style.display = '';
609 ae.dom.style.visibility = 'visible';
616 var ae = this.getActionEl();
617 ae.dom.style.display = 'none';
621 * The function that should handle the trigger's click event. This method does nothing by default until overridden
622 * by an implementing function.
624 * @param {EventObject} e
626 onTriggerClick : Roo.emptyFn