1

I am trying to show a message to user if email address is already registered or message saying "thanks for signing up!"

Form 1:

<div>
    <button type="submit" data-target="#publisherVerification">Sign up</button>
</div>

<div id="publisherVerification" ng-if="flag===true">
    <div>
        <p>Thank you for signing up.</p>
    </div>
</div>

<div id="publisherVerification" ng-if="flag===false">
    <div>
        <p>User already registered. Please use login.</p>
    </div>
</div>

Form 2:

<div>
    <button type="submit"  data-target="#artistVerification">Sign up</button>
</div>

<div id="artistVerification" ng-if="flag === true">
    <div>
        <p>Thank you for signing up</p>
    </div>
    <div id="artistVerification" ng-if="flag === false">
        <div>
            <p>User already registered. Please use login.</p>
        </div>
    </div>
</div>

Both the above forms are in the same page and calling same function on button click.

Its working but both forms are displaying messages if the user is "already register or new user" because they are calling same function. How do I show message for particular form only. I know I can create separate function for each form but I want try it with single function.

2 Answers 2

2

The issue is that both ng-ifs are using the same flags. You'll need to differentiate between the artist flag and the publisher flag.

Also, there should be a flag which hides the message at the start, only revealing when the user has submitted.

To solve this, I passed a user parameter to the shared submit function.

<button type="submit" ng-click='submitForm( "publisher" )' data-target="#publisherVerification">Sign up</button>

<div id="publisherVerification" ng-if="submitted.publisher ===true">
   <div ng-if="flags.publisher===true">
     <p>Thank you for signing up.</p>
   </div>
   <div ng-if="flags.publisher===false">
      <p>User already registered. Please use login.</p>
    </div>
   </div>  
</div>

Here's a JSFiddle with a working solution: https://jsfiddle.net/adamback42/x50kyh6n/4/

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

1 Comment

Thank you so much :) I am still testing it.
0

use different object to show different messages, eg: set publisherVerification.flag = true, when the publisherVerification is successful for signup else set publisherVerification.flag = false;

similar for the artistVerification use artistVerification.true when artistVerification is successful for signup else set false for artistVerification.flag;

this will help you separate your code for publisherVerification and artistVerification which is much more cleaner.

1 Comment

different objects?

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.