2

Does anyone know how to add the input-lg class to my ui-select directive? I am using the angularJs ui-select with the bootstrap theme.

I have tried

<ui-select ng-model="link.closer.data" class="input-lg">

I have also looked at the select.js file and tried adding input-lg but nothing seems to work

2
  • If you inspect the ui-select, does it have the class, or is it removed? Commented Jul 8, 2015 at 13:18
  • The uiSelect directive has replace:true in it's config. Anything you add to that element will be removed. The docs and code have no way of adding custom classes from a quick scan over. Commented Jul 8, 2015 at 13:19

2 Answers 2

2

I had the same problem. I solved it with css.

.ui-select-bootstrap>.ui-select-match>.btn,
.form-control:focus {
    height: 46px;
    padding: 10px 16px;
    font-size: 18px;
    line-height: 1.3333333;
    border-radius: 6px;
}
Sign up to request clarification or add additional context in comments.

Comments

0

The uiSelect directive has replace:true in it's config. Anything you add to that element will be removed. The docs and code have no way of adding custom classes from a quick scan over.

However the implementation does have a concept of themes. This is defined as an attribute on the directives element. There are a number of themes built in.

  • bootstrap
  • select2
  • selectize

For example to use these themes you would use:

// Bootstrap
<ui-select ng-model="link.closer.data" theme="bootstrap">

// Select 2
<ui-select ng-model="link.closer.data" theme="select2">

// Selectize
<ui-select ng-model="link.closer.data" theme="selectize">

If you look at the code that loads in the templates, you'll see the following in the templateUrl property.

templateUrl: function(tElement, tAttrs) {
    var theme = tAttrs.theme || uiSelectConfig.theme;
    return theme + (angular.isDefined(tAttrs.multiple) ? 
        '/select-multiple.tpl.html' : 
        '/select.tpl.html');
}

So angular will load the correct theme based on the directive attribute or use the default value from the configuration.

As a workaround, you could create your own theme by building the templates for them.

// Note the location for my theme is "mytheme/select.tpl.html"
// making my theme name: "mytheme"
angular.module("customSelect")
    .run(["$templateCache", function($templateCache {
        $templateCache.put("mytheme/select.tpl.html",
            "<p>my custom html here<\/p>";
    ]});

An easy way to do this is to open up the ui-select/dist/select.js scroll to the bottom. Copy all the templateCache declarations for bootstrap. Paste them into your own project and modify the theme name and the html, including your class input-lg.

Now include your theme name as the theme in the directive.

<ui-select ng-model="link.closer.data" theme="mytheme">

And to use the native

<ui-select ng-model="link.closer.data">

Or

<ui-select ng-model="link.closer.data" theme="bootstrap">

Now you have full control over the HTML generated by the directive including all classnames etc without modifying the core code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.