Home Ionic 3 - Validate inputs with the same name
Reply: 0

Ionic 3 - Validate inputs with the same name

Mike Wells
Mike Wells Published in 2018-02-13 14:53:13Z

I am in Ionic 3. I have a JSON feed that has lots of questions in it.

I can grab the feed and display all the questions no problems. I just want to validate the answer areas as not null or not empty. I can target a field like a username or password by name, no problems. In PHP/HTML I'd use a field name of 'answer[]' and then check each one in turn. I'm just a bit lost as to how to do this in Ionic.

Thanks in advance. [edited]

My JSON feed is this:

    {"question":"Question 1"},
    {"question":"Question 2"},
    {"question":"Question 3"}

I then set the data like this in the ts:

var JSONObject = myStaticData.data;
this.questions = JSONObject;

Then in view I do this to show them:

    <div *ngFor="let question of questions; let i = index;" class="question-item clearfix">
      <div class="question clearfix">
        <span class="number">{{ i + 1 }}.</span>
        <p>{{ question.question }}</p>
      <textarea name="question[{{ i }}]" placeholder="Answer copy in here"></textarea>

How do I validate each textarea to not be empty?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.342282 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO