Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 185757
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 10, 20222022-06-10T05:58:36+00:00 2022-06-10T05:58:36+00:00

html – AngularJS Selects Empty Option Even Valid Option is Avaliable

  • 0

[ad_1]

I’m using AngularJS ver. 1.2.15 on my project. And, I have a select element on one of my views as per below:

<select class="select-white form-control form-select" id="cat2_{{feed.id}}" ng-model="feed.operationstatusid" ng-change="updateCategoryAndStatus(feed, true)"></select>

And, I’m feeding this element like this:

    function SetCategory2(cat1Id, feed) {
        var feedId = feed.id;

        var fromRuleOpStatusId = -1;

        $('#cat2_' + feedId).find('option').remove();

        if (cat1Id > -1) {
            $('#cat2_' + feedId).append($('<option></option>').text(lang.SelectSubCategory).val(0));

            $.each($scope.category2, function (index, cat2Item) {
                $('#cat2_' + feedId).append($('<option></option>').text(cat2Item.statusdescription).val(cat2Item.id));
            });

            var isselected = false;

            $.each($scope.category2, function (index, cat2Item) {
                if (feed.operationstatusid == cat2Item.id) {
                    $('#cat2_' + feedId).val(cat2Item.id);

                    fromRuleOpStatusId = -1;

                    isselected = true;
                }
                else {
                    var feedStr = "";

                    if (feed.title != undefined && feed.title != null) {
                        feedStr = feed.title.toLowerCase();
                    }

                    if ($scope.catTitleRulesTwo) {
                        $.each($scope.catTitleRulesTwo, function (r_index, r_item) {
                            if (cat2Item.id == r_item.titleCode && !isselected) {
                                if (feedStr != undefined && feedStr != null && r_item != undefined && r_item != null) {
                                    String.prototype.contains = function (str) { return this.toLowerCase().indexOf(str) !== -1; };

                                    var text = feedStr;

                                    if (eval(r_item.ruleexpression)) {
                                        $('#cat2_' + feedId).val(cat2Item.id);

                                        fromRuleOpStatusId = cat2Item.id;

                                        isselected = true;
                                    }
                                }
                            }
                        });
                    }
                }
            });

            if (fromRuleOpStatusId != -1) {
                feed.operationstatusid = fromRuleOpStatusId;
            }
        }
        else {
            $('#cat2_' + feedId).append($('<option></option>').text(lang.SelectSubCategory).val(0));
        }
    }

I am aware of the facts about eval function, but the project I’m working on is quite old, so does the code. Anyway, this is about business logic and quite irrelevant with the thing I’m going to ask (or so I was thinking).

As you can see I’m appending all the options before I set the value of the selectbox with using .val(...). I have also checked that values do match along with the data types. But, when I observe this function step by step, I saw that selected value does show up without flaw. After the code finish with my above mentioned function (SetCategory2), code goes through on of the function located on AngularJS file, named xhr.onreadystatechange. It’s not a long function, so I’m sharing it also on below.

      xhr.onreadystatechange = function() {
        if (xhr && xhr.readyState == 4) {
          var responseHeaders = null,
              response = null;

          if(status !== ABORTED) {
            responseHeaders = xhr.getAllResponseHeaders();

            response = ('response' in xhr) ? xhr.response : xhr.responseText;
          }

          completeRequest(callback,
              status || xhr.status,
              response,
              responseHeaders);
        }
      };

After the code released from this function, respective selectbox’s value is pointed at the empty option.

I have run into topics which talks about this behaviour might due to invalid option-value match, but as I described above, I append all my options before deciding the value. So, I can’t figure out what I’m missing.

Thank you in advance.

[ad_2]

  • 0 0 Answers
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 325 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 295 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 292 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.