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: 'root-select2-choices',
209 cls: 'root-select2-search-field',
222 cls: 'root-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 += ' root-select2-container-multi';
271 if (align ==='left' && this.fieldLabel.length) {
273 // Roo.log("left and has label");
279 cls : 'control-label col-sm-' + this.labelWidth,
280 html : this.fieldLabel
284 cls : "col-sm-" + (12 - this.labelWidth),
291 } else if ( this.fieldLabel.length) {
292 // Roo.log(" label");
297 //cls : 'input-group-addon',
298 html : this.fieldLabel
308 // Roo.log(" no label && no align");
315 ['xs','sm','md','lg'].map(function(size){
316 if (settings[size]) {
317 cfg.cls += ' col-' + size + '-' + settings[size];
328 onResize : function(w, h){
329 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
330 // if(typeof w == 'number'){
331 // var x = w - this.trigger.getWidth();
332 // this.inputEl().setWidth(this.adjustWidth('input', x));
333 // this.trigger.setStyle('left', x+'px');
338 adjustSize : Roo.BoxComponent.prototype.adjustSize,
341 getResizeEl : function(){
342 return this.inputEl();
346 getPositionEl : function(){
347 return this.inputEl();
351 alignErrorIcon : function(){
352 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
356 initEvents : function(){
360 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
361 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
362 if(!this.multiple && this.showToggleBtn){
363 this.trigger = this.el.select('span.dropdown-toggle',true).first();
364 if(this.hideTrigger){
365 this.trigger.setDisplayed(false);
367 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
371 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
374 if(this.removable && !this.editable && !this.tickable){
375 var close = this.closeTriggerEl();
378 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
379 close.on('click', this.removeBtnClick, this, close);
383 //this.trigger.addClassOnOver('x-form-trigger-over');
384 //this.trigger.addClassOnClick('x-form-trigger-click');
387 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
391 closeTriggerEl : function()
393 var close = this.el.select('.roo-combo-removable-btn', true).first();
394 return close ? close : false;
397 removeBtnClick : function(e, h, el)
401 if(this.fireEvent("remove", this) !== false){
403 this.fireEvent("afterremove", this)
407 createList : function()
409 this.list = Roo.get(document.body).createChild({
411 cls: 'typeahead typeahead-long dropdown-menu',
412 style: 'display:none'
415 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
420 initTrigger : function(){
425 onDestroy : function(){
427 this.trigger.removeAllListeners();
428 // this.trigger.remove();
431 // this.wrap.remove();
433 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
437 onFocus : function(){
438 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
441 this.wrap.addClass('x-trigger-wrap-focus');
442 this.mimicing = true;
443 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
445 this.el.on("keydown", this.checkTab, this);
452 checkTab : function(e){
453 if(e.getKey() == e.TAB){
464 mimicBlur : function(e, t){
466 if(!this.wrap.contains(t) && this.validateBlur()){
473 triggerBlur : function(){
474 this.mimicing = false;
475 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
477 this.el.un("keydown", this.checkTab, this);
479 //this.wrap.removeClass('x-trigger-wrap-focus');
480 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
484 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
485 validateBlur : function(e, t){
490 onDisable : function(){
491 this.inputEl().dom.disabled = true;
492 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
494 // this.wrap.addClass('x-item-disabled');
499 onEnable : function(){
500 this.inputEl().dom.disabled = false;
501 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
503 // this.el.removeClass('x-item-disabled');
509 var ae = this.getActionEl();
512 ae.dom.style.display = '';
513 ae.dom.style.visibility = 'visible';
520 var ae = this.getActionEl();
521 ae.dom.style.display = 'none';
525 * The function that should handle the trigger's click event. This method does nothing by default until overridden
526 * by an implementing function.
528 * @param {EventObject} e
530 onTriggerClick : Roo.emptyFn