0

I am new to angular js and writing directive to display the password strength.

Here is the fiddle - https://jsfiddle.net/user_123/3hruj8ce/12/

 <span  data-ng-show='passwordForm.password.$valid && passwordForm.password.$dirty' data-ng-class="strength">
     <li class="point"></li >      
     <li  class="point"></li>
     <li  class="point"></li>         
     <li  class="point"></li> 
</span>

I am having trouble updating the colour of li as user starts entering the password.

Any help much appreciated.

Thanks in advance.

UPDATE:

this is the updated fiddle (still not working as expected..) - https://jsfiddle.net/user_123/3hruj8ce/13/

1
  • how do you link "strength" to your directive ? how is this variable being updated ? Commented May 18, 2016 at 13:45

3 Answers 3

1

Your strength computing formula return always 1 most of the time unless you type a crazy string as a password.

Anyway for fixing the css class (strong medium and weak), you need to change

.strong   { color: #060; border-color: #0F0;}

to

.strong > li.point   { background-color: #060; border-color: #0F0;}

and change your formula to lower the strength I believe.

update : for targeting one, two or 3 li you may add your classes to the li as follow

<li class="point weak"><li>
<li class="point weak medium"><li>
<li class="point weak medium strong"><li>

and change css to

.strong > li.strong{background-color: #060; border-color: #0F0;}
.medium > li.medium{background-color: #080; border-color: #0F0;}
.weak > li.weak{background-color: #099; border-color: #0F0;}
Sign up to request clarification or add additional context in comments.

2 Comments

What I wrote just fix your first fiddle not the second one.
thanks for the answer. i updated the fidde - jsfiddle.net/user_123/3hruj8ce/20 .But now the problem is all the li's are turning to red when a poor password is entered, I want only the first first li to turn red and last 3 li's to remain in same color. same for other colors as well.. any idea how to achieve this?
1

I have updated fiddle https://jsfiddle.net/3hruj8ce/14/

The li elements color should be changed by changing their class name to strong/medium/weak. Please check.

1 Comment

hey, i see the color is changing for all the li's. i want the li's to be updated one by one as the user is typing. if it is medium first three li's should be amber and last li to remian in the same color, if weak 2 li's should be red and last 2 li's in same color, if strong all the li's should turn green
0

It seems like you haven't defined these:

.strong   { color: #060; border-color: #0F0;}
.medium   { color: #C60; border-color: #FC0;}
.weak     { color: #900; border-color: #F00;}

In your list/HTML.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.