0

I'm trying to get the second password input only to show after the user starts typing into the first input. Also, is there are way to either "require" them both or none at all?

<form name="signUpForm">
    ...

    <input ng-modal="password" type="password" placeholder="password">
    <input ng-show="password.$dirty" class="animate-show animate-hide" type="password" placeholder="password (again)">
</form>
2
  • ng-modal must be ng-model. Your input must have a name ("password" for example), and the correct way to access its dirty flag is to use signupForm.password.$dirty. Commented May 19, 2015 at 22:14
  • 1
    @Jackson, the angularjs docs show good examples here: docs also see the answer i posted below which uses $valid and required. GL! Commented May 19, 2015 at 23:17

2 Answers 2

1

password has no property like $dirty but form controller has that one. So first of set name of input then you can access form controller with it

<form name="signUpForm">
...

    <input name="passwordNameAttr" ng-modal="password" type="password" placeholder="password">
    <input ng-show="signUpForm.passwordNameAttr.$dirty" class="animate-show animate-hide" type="password" placeholder="password (again)">
</form>

for dynamic require you can use ng-required. Just put an expresion on it and depends on condition your fields will be required or not...

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure why it's not animating but at least my extra input shows/hides now.
1

another example using ng-show $valid required for input fields ..

html:

<form name="signUpForm">
   <input name="firstPassword" ng-model="first.password" type="password" placeholder="password" required>
   <input name="secondPassword" ng-show="signUpForm.firstPassword.$valid" ng-model="second.password" type="password" placeholder="password (again)" required>
</form> 

working fiddle here: https://jsfiddle.net/vj5evgyw/2/

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.