Display Mat-hint only on corresponding input focus












0















I have a mat-hint element added in my html.
I want to display mat-hint only when users focus is on corresponding form-field & hide the hint on focusout.
How to achieve this scenario for all form-fields.



<mat-hint align="end">Max 50 characters</mat-hint>









share|improve this question



























    0















    I have a mat-hint element added in my html.
    I want to display mat-hint only when users focus is on corresponding form-field & hide the hint on focusout.
    How to achieve this scenario for all form-fields.



    <mat-hint align="end">Max 50 characters</mat-hint>









    share|improve this question

























      0












      0








      0








      I have a mat-hint element added in my html.
      I want to display mat-hint only when users focus is on corresponding form-field & hide the hint on focusout.
      How to achieve this scenario for all form-fields.



      <mat-hint align="end">Max 50 characters</mat-hint>









      share|improve this question














      I have a mat-hint element added in my html.
      I want to display mat-hint only when users focus is on corresponding form-field & hide the hint on focusout.
      How to achieve this scenario for all form-fields.



      <mat-hint align="end">Max 50 characters</mat-hint>






      angular angular-material






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 11:05









      Mayur PatilMayur Patil

      287




      287
























          1 Answer
          1






          active

          oldest

          votes


















          2














          You can use (focus) and (focusout) with reference called focusState



          <input name="date" type="text" (focus)="focusState='true'" (focusout)="focusState='false'">
          <mat-hint align="end" *ngIf="focusState == 'true'">Max 50 characters</mat-hint>


          Edit



          To handle the multiple items



          <div *ngFor="let item of array">
          <input #item name="date" type="text" (focus)="item.alt='true'" (focusout)="item.alt='false'">
          <mat-hint align="end" *ngIf="item.alt == 'true'">Max 50 characters</mat-hint>
          </div>





          share|improve this answer


























          • I loved the solution. I have used this stuff for other use cases. The problem i am facing is little different. I am having a formArray which is bulk saved. If I set this declare this variable all the inputs will be affected.If i modify object my ngrx store will be impacted. hence confused what would be idle solution to such problems

            – Mayur Patil
            Nov 14 '18 at 11:12











          • It looks like you want to handle the multiple items of formArray. You might be using *ngFor for iteration. For such kind of scenario, you can create a separate variable which for each items and performs the same operation independently. Update the answer and here the link which will help to implement this. stackblitz.com/edit/angular-ckqmvs

            – Sunil Singh
            Nov 14 '18 at 11:40











          • Yes, this is the solution i am using, by adding property in each object. i was looking for solution without modifying my actual object. but thats ok, i will stick with object alteration for now. Thanks for your help

            – Mayur Patil
            Nov 15 '18 at 5:31











          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%2f53279637%2fdisplay-mat-hint-only-on-corresponding-input-focus%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          You can use (focus) and (focusout) with reference called focusState



          <input name="date" type="text" (focus)="focusState='true'" (focusout)="focusState='false'">
          <mat-hint align="end" *ngIf="focusState == 'true'">Max 50 characters</mat-hint>


          Edit



          To handle the multiple items



          <div *ngFor="let item of array">
          <input #item name="date" type="text" (focus)="item.alt='true'" (focusout)="item.alt='false'">
          <mat-hint align="end" *ngIf="item.alt == 'true'">Max 50 characters</mat-hint>
          </div>





          share|improve this answer


























          • I loved the solution. I have used this stuff for other use cases. The problem i am facing is little different. I am having a formArray which is bulk saved. If I set this declare this variable all the inputs will be affected.If i modify object my ngrx store will be impacted. hence confused what would be idle solution to such problems

            – Mayur Patil
            Nov 14 '18 at 11:12











          • It looks like you want to handle the multiple items of formArray. You might be using *ngFor for iteration. For such kind of scenario, you can create a separate variable which for each items and performs the same operation independently. Update the answer and here the link which will help to implement this. stackblitz.com/edit/angular-ckqmvs

            – Sunil Singh
            Nov 14 '18 at 11:40











          • Yes, this is the solution i am using, by adding property in each object. i was looking for solution without modifying my actual object. but thats ok, i will stick with object alteration for now. Thanks for your help

            – Mayur Patil
            Nov 15 '18 at 5:31
















          2














          You can use (focus) and (focusout) with reference called focusState



          <input name="date" type="text" (focus)="focusState='true'" (focusout)="focusState='false'">
          <mat-hint align="end" *ngIf="focusState == 'true'">Max 50 characters</mat-hint>


          Edit



          To handle the multiple items



          <div *ngFor="let item of array">
          <input #item name="date" type="text" (focus)="item.alt='true'" (focusout)="item.alt='false'">
          <mat-hint align="end" *ngIf="item.alt == 'true'">Max 50 characters</mat-hint>
          </div>





          share|improve this answer


























          • I loved the solution. I have used this stuff for other use cases. The problem i am facing is little different. I am having a formArray which is bulk saved. If I set this declare this variable all the inputs will be affected.If i modify object my ngrx store will be impacted. hence confused what would be idle solution to such problems

            – Mayur Patil
            Nov 14 '18 at 11:12











          • It looks like you want to handle the multiple items of formArray. You might be using *ngFor for iteration. For such kind of scenario, you can create a separate variable which for each items and performs the same operation independently. Update the answer and here the link which will help to implement this. stackblitz.com/edit/angular-ckqmvs

            – Sunil Singh
            Nov 14 '18 at 11:40











          • Yes, this is the solution i am using, by adding property in each object. i was looking for solution without modifying my actual object. but thats ok, i will stick with object alteration for now. Thanks for your help

            – Mayur Patil
            Nov 15 '18 at 5:31














          2












          2








          2







          You can use (focus) and (focusout) with reference called focusState



          <input name="date" type="text" (focus)="focusState='true'" (focusout)="focusState='false'">
          <mat-hint align="end" *ngIf="focusState == 'true'">Max 50 characters</mat-hint>


          Edit



          To handle the multiple items



          <div *ngFor="let item of array">
          <input #item name="date" type="text" (focus)="item.alt='true'" (focusout)="item.alt='false'">
          <mat-hint align="end" *ngIf="item.alt == 'true'">Max 50 characters</mat-hint>
          </div>





          share|improve this answer















          You can use (focus) and (focusout) with reference called focusState



          <input name="date" type="text" (focus)="focusState='true'" (focusout)="focusState='false'">
          <mat-hint align="end" *ngIf="focusState == 'true'">Max 50 characters</mat-hint>


          Edit



          To handle the multiple items



          <div *ngFor="let item of array">
          <input #item name="date" type="text" (focus)="item.alt='true'" (focusout)="item.alt='false'">
          <mat-hint align="end" *ngIf="item.alt == 'true'">Max 50 characters</mat-hint>
          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 11:46

























          answered Nov 13 '18 at 11:25









          Sunil SinghSunil Singh

          6,2022626




          6,2022626













          • I loved the solution. I have used this stuff for other use cases. The problem i am facing is little different. I am having a formArray which is bulk saved. If I set this declare this variable all the inputs will be affected.If i modify object my ngrx store will be impacted. hence confused what would be idle solution to such problems

            – Mayur Patil
            Nov 14 '18 at 11:12











          • It looks like you want to handle the multiple items of formArray. You might be using *ngFor for iteration. For such kind of scenario, you can create a separate variable which for each items and performs the same operation independently. Update the answer and here the link which will help to implement this. stackblitz.com/edit/angular-ckqmvs

            – Sunil Singh
            Nov 14 '18 at 11:40











          • Yes, this is the solution i am using, by adding property in each object. i was looking for solution without modifying my actual object. but thats ok, i will stick with object alteration for now. Thanks for your help

            – Mayur Patil
            Nov 15 '18 at 5:31



















          • I loved the solution. I have used this stuff for other use cases. The problem i am facing is little different. I am having a formArray which is bulk saved. If I set this declare this variable all the inputs will be affected.If i modify object my ngrx store will be impacted. hence confused what would be idle solution to such problems

            – Mayur Patil
            Nov 14 '18 at 11:12











          • It looks like you want to handle the multiple items of formArray. You might be using *ngFor for iteration. For such kind of scenario, you can create a separate variable which for each items and performs the same operation independently. Update the answer and here the link which will help to implement this. stackblitz.com/edit/angular-ckqmvs

            – Sunil Singh
            Nov 14 '18 at 11:40











          • Yes, this is the solution i am using, by adding property in each object. i was looking for solution without modifying my actual object. but thats ok, i will stick with object alteration for now. Thanks for your help

            – Mayur Patil
            Nov 15 '18 at 5:31

















          I loved the solution. I have used this stuff for other use cases. The problem i am facing is little different. I am having a formArray which is bulk saved. If I set this declare this variable all the inputs will be affected.If i modify object my ngrx store will be impacted. hence confused what would be idle solution to such problems

          – Mayur Patil
          Nov 14 '18 at 11:12





          I loved the solution. I have used this stuff for other use cases. The problem i am facing is little different. I am having a formArray which is bulk saved. If I set this declare this variable all the inputs will be affected.If i modify object my ngrx store will be impacted. hence confused what would be idle solution to such problems

          – Mayur Patil
          Nov 14 '18 at 11:12













          It looks like you want to handle the multiple items of formArray. You might be using *ngFor for iteration. For such kind of scenario, you can create a separate variable which for each items and performs the same operation independently. Update the answer and here the link which will help to implement this. stackblitz.com/edit/angular-ckqmvs

          – Sunil Singh
          Nov 14 '18 at 11:40





          It looks like you want to handle the multiple items of formArray. You might be using *ngFor for iteration. For such kind of scenario, you can create a separate variable which for each items and performs the same operation independently. Update the answer and here the link which will help to implement this. stackblitz.com/edit/angular-ckqmvs

          – Sunil Singh
          Nov 14 '18 at 11:40













          Yes, this is the solution i am using, by adding property in each object. i was looking for solution without modifying my actual object. but thats ok, i will stick with object alteration for now. Thanks for your help

          – Mayur Patil
          Nov 15 '18 at 5:31





          Yes, this is the solution i am using, by adding property in each object. i was looking for solution without modifying my actual object. but thats ok, i will stick with object alteration for now. Thanks for your help

          – Mayur Patil
          Nov 15 '18 at 5:31


















          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%2f53279637%2fdisplay-mat-hint-only-on-corresponding-input-focus%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







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation