vitalets / angular-xeditable

Edit in place for AngularJS
http://vitalets.github.io/angular-xeditable
MIT License
1.91k stars 403 forks source link

Add value to dropdown #661

Open SebastianCBA opened 7 years ago

SebastianCBA commented 7 years ago

I have a listbox that gets the data from the database:

            <span editable-select="sectorSheet.economy_id" e-name="economy_id" onshow="loadEconomies()" e-form="rowform" e-ng-options="e.id as e.text for e in economies">
           [[ showEconomy(sectorSheet) ]]
            </span>        

          $scope.loadEconomies = function() {
            return $scope.economies.length ? null : $http.get('Economy/json').success(function(data) {
              $scope.economies = data;
            });
          }; 

I need to be able to add a new value to the dropdown. Some help will be very grateful

ckosloski commented 7 years ago

Do you want the user to be able to add an item to the list or do you need to programmatically add an item to the list? If the second one, I think you should just be able to do a economies.push(<your new object>)

SebastianCBA commented 7 years ago

Yes, I want the user to be able to add an item to the list

Like http://embed.plnkr.co/GLuyC0jpIdiEXB6R4FIa/preview

But I do not know how to apply it.

ckosloski commented 7 years ago

ui-select is supported, please see the documentation.

SebastianCBA commented 7 years ago

Yes..

            <div editable-ui-select="sectorSheet.economy_id" data-e-form="rowform" data-e-name="economy_id" name="economy_id" theme="bootstrap" data-e-ng-model="sectorSheet.economy_id">
              [[ showEconomy(sectorSheet) ]]
                <editable-ui-select-match placeholder="Select">
                [[showEconomy(sectorSheet) || $select.search]]
            </editable-ui-select-match>
            <editable-ui-select-choices repeat="economy in (search_economies | filter: {text: $select.search}) track by economy.id">
                    [[ economy.text ]]
            </editable-ui-select-choices>
        </div>

It seems to work as an example, but how to add a new economy? Or write a value that does not exist in the dropdown?

ckosloski commented 7 years ago

You need to use tagging. Please see the ui-select documentation.