leocaseiro / angular-chosen

AngularJS Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a AngularJS way
http://leocaseiro.github.io/angular-chosen/
MIT License
682 stars 248 forks source link

Question: setting default values for all chosen selects on the page #226

Closed DanielFurmanov closed 7 years ago

DanielFurmanov commented 7 years ago

Greetings!

How do I set

// taken from JQuery plugin 
AbstractChosen.default_multiple_text = "Select Some Options";
AbstractChosen.default_single_text = "Select an Option";
AbstractChosen.default_no_result_text = "No results match";

those variables to some other values, when including localytics.directives ?

In other words: how to set default settings for all of chosen-selects on the page

leocaseiro commented 7 years ago

Hi @DanielFurmanov,

As you can see on the documentation, you must use the same names, switching from _ to -, like so:

Example from docs: http://leocaseiro.github.io/angular-chosen/#translate24

<select multiple chosen
    no-results-text="'Nenhum resultado encontrado para'"
    placeholder-text-multiple="'Selecione as opções'"
    ng-model="state" ng-options="s for s in states">
    <option value=""></option>
</select>
DanielFurmanov commented 7 years ago

@leocaseiro Thank you for your answer! Being a non-native language speaker I must have expressed myself not so clear.

I have ~10 selects on the page, is there an option in angular-chosen-directive to declare a default placeholder (and etc) for all of them in one place, not in every select tag?

What I am doing now in my js:

$scope.textSingleChosenPlaceholder = 'Select something';
$scope.noResultsChosenPlaceholder = 'Nothing found';

And in html:

<select multiple chosen
    no-results-text="'textSingleChosenPlaceholder'"
    placeholder-text-single="'noResultsChosenPlaceholder'"    
    <option value=""></option>
</select>

And what I want to do is something like that:

angular.module('App', ['localytics.directives'])
.run(function( localyticsDirectivesOptions ) {
       //set default placeholder for any chosen-select on the page
       localyticsDirectivesOptions.placeholder_text_single = 'blabla choose smthng';
    });
leocaseiro commented 7 years ago

Hi @DanielFurmanov, Unfortunately, there's no Angular.config for angular-chosen at the moment. There's an issue about that #77, however, I've never had the time to implement (Accepting PR).

You could use some variables to use on your <select>, like so:

<select multiple ng-model="example1" chosen no-results-text="noResultsText"></select>
<select multiple ng-model="example3" chosen no-results-text="noResultsText"></select>
<select multiple ng-model="example2" chosen no-results-text="noResultsText"></select>
$scope.noResultsText = 'My Custom Text';

I'll close this issue in regards to the #77