Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have two options in HTML select input with values as
C#
AbhiNAV5
RaviNATH6

User selects one of these values and that will be stored in DB.
If any user directly changes the value in DB as `ABHINAV5 or abhinav5` or `RAVINATH6 or ravinath6` (or possibly however he wants in any case),
then I am not able to show the value in dropdown. Instead it adds a blank entry

Here is HTML
ASP.NET
<select id="Select1" clientidmode="Static" class="htmlDropdown"  runat="server" data-ng-disabled="!PropCollection.IsConfigured" data-ng-model="PropCollection.ViewerName" style="width: 150px;" tabindex="2">
            <option value="AbhiNAV5">AbhiNAV5</option>
            <option value="RaviNATH6">RaviNATH6</option>
  </select>


Is there any way to handle the case? I want it to be case insensitive.

Any help appreciated.
Thanks.

What I have tried:

I tried using filter but it showed no effect. Or perhaps I don't how to use it in a better way.
I tried this as

<select id="Select1" clientidmode="Static" class="htmlDropdown" runat="server" data-ng-disabled="!PropCollection.IsConfigured" data-ng-model="PropCollection.ViewerName | filter: false" style="width: 150px;" tabindex="2">
<option value="AbhiNAV5">AbhiNAV5</option>
<option value="RaviNATH6">RaviNATH6</option>
</select>
Posted
Updated 17-May-16 23:50pm

Hi Lokesh,

Try using ng-options.

assuming your 'PropCollection' is an array of form:

JavaScript
$scope.PropCollection = [{"ViewerName":"AbhiNAV5"},{"ViewerName":"RaviNATH6"}];


under your js file (or tag)
mention the following

//to show default value in dropdown controll


JavaScript
$scope.viewName = PropCollection[0].ViewerName; 


and try building html like this
HTML
<select ng-model="viewName" ng-options="view.ViewName for view in PropCollection">
</select>


Now you can access the selected value using "viewName".

For dropdowns you have a predefined directive called ng-options.

See this plnkr for reference.

Plunker for ng-Options
 
Share this answer
 
Comments
Lokesh Zende 18-May-16 4:36am    
Surya,
AbhiNAV5 and RaviNATH6 are my hardcoded options in select input, so I have no trouble binding the data. I can even show the value that comes from db using ng-model.
Problem occurs when that value is not exactly same in case as that of values of options hardcoded.
Here's what I did.
I changed the model to lowercase and the values of the option values to lowercase. Now they match up when they are bound.
 
Share this answer
 
try this

HTML
<!DOCTYPE html>
<html lang="en-US">
<head>
    <script src="angular.js"></script>
    <script src="jquery.js"></script>
    <!--<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>-->
    <script>
        var app = angular.module('myapp', []);
        app.controller('myctrl', myctrl);
         

        function myctrl($scope) {

            var find = 'ABhiNAV5';
           
            var options = document.getElementById('Select1').options;
            for (var i = 0; i < options.length; i++) {
                if (angular.lowercase(options[i].value) == angular.lowercase(find)) {
                    $scope.ViewerName = options[i].value;
                    break;
                }
            }
        }
    </script>



</head>
<body>

    <div ng-app="myapp" ng-init="showhide=true" ng-controller="myctrl"> 


        <select id="Select1" class="htmlDropdown" data-ng-model="ViewerName" style="width: 150px;" tabindex="2">
            <option value="aa">aa</option>
            <option value="AbhiNAV5">AbhiNAV5</option>
            <option value="RaviNATH6">RaviNATH6</option>
        </select>


    </div>


</body>
</html>


demo - JSFiddle[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900