How to display div based on selected multiselect












0















I am trying to show/hide elements based on multiselect dropdown, but my code doesn't seem to work. For example, one of the data for nameList is Name, and when Name is selected, I would like to display a div with another drop-down menu. I am using Angular and Typescript. Below are my codes for your reference:



<kendo-multiselect [data]="nameList" [(ngModel)]="selectedname "></kendo-multiselect>


<div *ngIf="selectedname === 'Name'">
<div class="col-4">
You selected {{selectedname}}
</div>
<div class="col-2">Name:</div>
<div class="col-6">
<kendo-dropdownlist style="width: 100%" [data]="anotherList" [valuePrimitive]="true"></kendo-dropdownlist>
</div>
</div>









share|improve this question























  • Hey, can you put the You selected {{selectedname}} line outside the if, and just below the first kendo-multiselect and show me the output? You are treating like the selectedname will be a string, but I suspect its an Object since it doesnt have to store only one name.

    – user8401765
    Nov 21 '18 at 5:33
















0















I am trying to show/hide elements based on multiselect dropdown, but my code doesn't seem to work. For example, one of the data for nameList is Name, and when Name is selected, I would like to display a div with another drop-down menu. I am using Angular and Typescript. Below are my codes for your reference:



<kendo-multiselect [data]="nameList" [(ngModel)]="selectedname "></kendo-multiselect>


<div *ngIf="selectedname === 'Name'">
<div class="col-4">
You selected {{selectedname}}
</div>
<div class="col-2">Name:</div>
<div class="col-6">
<kendo-dropdownlist style="width: 100%" [data]="anotherList" [valuePrimitive]="true"></kendo-dropdownlist>
</div>
</div>









share|improve this question























  • Hey, can you put the You selected {{selectedname}} line outside the if, and just below the first kendo-multiselect and show me the output? You are treating like the selectedname will be a string, but I suspect its an Object since it doesnt have to store only one name.

    – user8401765
    Nov 21 '18 at 5:33














0












0








0








I am trying to show/hide elements based on multiselect dropdown, but my code doesn't seem to work. For example, one of the data for nameList is Name, and when Name is selected, I would like to display a div with another drop-down menu. I am using Angular and Typescript. Below are my codes for your reference:



<kendo-multiselect [data]="nameList" [(ngModel)]="selectedname "></kendo-multiselect>


<div *ngIf="selectedname === 'Name'">
<div class="col-4">
You selected {{selectedname}}
</div>
<div class="col-2">Name:</div>
<div class="col-6">
<kendo-dropdownlist style="width: 100%" [data]="anotherList" [valuePrimitive]="true"></kendo-dropdownlist>
</div>
</div>









share|improve this question














I am trying to show/hide elements based on multiselect dropdown, but my code doesn't seem to work. For example, one of the data for nameList is Name, and when Name is selected, I would like to display a div with another drop-down menu. I am using Angular and Typescript. Below are my codes for your reference:



<kendo-multiselect [data]="nameList" [(ngModel)]="selectedname "></kendo-multiselect>


<div *ngIf="selectedname === 'Name'">
<div class="col-4">
You selected {{selectedname}}
</div>
<div class="col-2">Name:</div>
<div class="col-6">
<kendo-dropdownlist style="width: 100%" [data]="anotherList" [valuePrimitive]="true"></kendo-dropdownlist>
</div>
</div>






angular typescript kendo-ui






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 5:13









Adibah Hanun Abu SemanAdibah Hanun Abu Seman

33




33













  • Hey, can you put the You selected {{selectedname}} line outside the if, and just below the first kendo-multiselect and show me the output? You are treating like the selectedname will be a string, but I suspect its an Object since it doesnt have to store only one name.

    – user8401765
    Nov 21 '18 at 5:33



















  • Hey, can you put the You selected {{selectedname}} line outside the if, and just below the first kendo-multiselect and show me the output? You are treating like the selectedname will be a string, but I suspect its an Object since it doesnt have to store only one name.

    – user8401765
    Nov 21 '18 at 5:33

















Hey, can you put the You selected {{selectedname}} line outside the if, and just below the first kendo-multiselect and show me the output? You are treating like the selectedname will be a string, but I suspect its an Object since it doesnt have to store only one name.

– user8401765
Nov 21 '18 at 5:33





Hey, can you put the You selected {{selectedname}} line outside the if, and just below the first kendo-multiselect and show me the output? You are treating like the selectedname will be a string, but I suspect its an Object since it doesnt have to store only one name.

– user8401765
Nov 21 '18 at 5:33












2 Answers
2






active

oldest

votes


















0














On change event of "kendo-mutliselecet" push selectedname item to "anotherList" then set kendo-dropdownlist [(ngModel)] to this selectedname.



<div *ngIf="selectedname.indexOf('Name')>=0">


I think it will be solution. Not tested.






share|improve this answer































    0














    Basically here selectedname returns an array, so you need to check whether an item exists in an array or not. So you can use the below code to check -



    <kendo-multiselect [data]="nameList" [(ngModel)]="selectedname "></kendo-multiselect>


    <div *ngIf="isShown('Name')">
    <div class="col-4">
    You selected {{selectedname}}
    </div>
    <div class="col-2">Name:</div>
    <div class="col-6">
    <kendo-dropdownlist style="width: 100%" [data]="anotherList" [valuePrimitive]="true"></kendo-dropdownlist>
    </div>
    </div>


    isShown(flag) {
    console.log(this.selectedname.indexOf(flag));
    if (this.selectedname.indexOf(flag) !== -1) {
    return true;
    } else {
    return false;
    }
    }


    Working example






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405622%2fhow-to-display-div-based-on-selected-multiselect%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      On change event of "kendo-mutliselecet" push selectedname item to "anotherList" then set kendo-dropdownlist [(ngModel)] to this selectedname.



      <div *ngIf="selectedname.indexOf('Name')>=0">


      I think it will be solution. Not tested.






      share|improve this answer




























        0














        On change event of "kendo-mutliselecet" push selectedname item to "anotherList" then set kendo-dropdownlist [(ngModel)] to this selectedname.



        <div *ngIf="selectedname.indexOf('Name')>=0">


        I think it will be solution. Not tested.






        share|improve this answer


























          0












          0








          0







          On change event of "kendo-mutliselecet" push selectedname item to "anotherList" then set kendo-dropdownlist [(ngModel)] to this selectedname.



          <div *ngIf="selectedname.indexOf('Name')>=0">


          I think it will be solution. Not tested.






          share|improve this answer













          On change event of "kendo-mutliselecet" push selectedname item to "anotherList" then set kendo-dropdownlist [(ngModel)] to this selectedname.



          <div *ngIf="selectedname.indexOf('Name')>=0">


          I think it will be solution. Not tested.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 5:34









          Serkan KONAKCISerkan KONAKCI

          15914




          15914

























              0














              Basically here selectedname returns an array, so you need to check whether an item exists in an array or not. So you can use the below code to check -



              <kendo-multiselect [data]="nameList" [(ngModel)]="selectedname "></kendo-multiselect>


              <div *ngIf="isShown('Name')">
              <div class="col-4">
              You selected {{selectedname}}
              </div>
              <div class="col-2">Name:</div>
              <div class="col-6">
              <kendo-dropdownlist style="width: 100%" [data]="anotherList" [valuePrimitive]="true"></kendo-dropdownlist>
              </div>
              </div>


              isShown(flag) {
              console.log(this.selectedname.indexOf(flag));
              if (this.selectedname.indexOf(flag) !== -1) {
              return true;
              } else {
              return false;
              }
              }


              Working example






              share|improve this answer




























                0














                Basically here selectedname returns an array, so you need to check whether an item exists in an array or not. So you can use the below code to check -



                <kendo-multiselect [data]="nameList" [(ngModel)]="selectedname "></kendo-multiselect>


                <div *ngIf="isShown('Name')">
                <div class="col-4">
                You selected {{selectedname}}
                </div>
                <div class="col-2">Name:</div>
                <div class="col-6">
                <kendo-dropdownlist style="width: 100%" [data]="anotherList" [valuePrimitive]="true"></kendo-dropdownlist>
                </div>
                </div>


                isShown(flag) {
                console.log(this.selectedname.indexOf(flag));
                if (this.selectedname.indexOf(flag) !== -1) {
                return true;
                } else {
                return false;
                }
                }


                Working example






                share|improve this answer


























                  0












                  0








                  0







                  Basically here selectedname returns an array, so you need to check whether an item exists in an array or not. So you can use the below code to check -



                  <kendo-multiselect [data]="nameList" [(ngModel)]="selectedname "></kendo-multiselect>


                  <div *ngIf="isShown('Name')">
                  <div class="col-4">
                  You selected {{selectedname}}
                  </div>
                  <div class="col-2">Name:</div>
                  <div class="col-6">
                  <kendo-dropdownlist style="width: 100%" [data]="anotherList" [valuePrimitive]="true"></kendo-dropdownlist>
                  </div>
                  </div>


                  isShown(flag) {
                  console.log(this.selectedname.indexOf(flag));
                  if (this.selectedname.indexOf(flag) !== -1) {
                  return true;
                  } else {
                  return false;
                  }
                  }


                  Working example






                  share|improve this answer













                  Basically here selectedname returns an array, so you need to check whether an item exists in an array or not. So you can use the below code to check -



                  <kendo-multiselect [data]="nameList" [(ngModel)]="selectedname "></kendo-multiselect>


                  <div *ngIf="isShown('Name')">
                  <div class="col-4">
                  You selected {{selectedname}}
                  </div>
                  <div class="col-2">Name:</div>
                  <div class="col-6">
                  <kendo-dropdownlist style="width: 100%" [data]="anotherList" [valuePrimitive]="true"></kendo-dropdownlist>
                  </div>
                  </div>


                  isShown(flag) {
                  console.log(this.selectedname.indexOf(flag));
                  if (this.selectedname.indexOf(flag) !== -1) {
                  return true;
                  } else {
                  return false;
                  }
                  }


                  Working example







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 5:33









                  Pardeep JainPardeep Jain

                  41.1k17103145




                  41.1k17103145






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405622%2fhow-to-display-div-based-on-selected-multiselect%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Xamarin.form Move up view when keyboard appear

                      Post-Redirect-Get with Spring WebFlux and Thymeleaf

                      Anylogic : not able to use stopDelay()