vendredi 15 avril 2016

AngularJs - PHP dynamic checkbox validation

In one of my application, I am creating a list of checkboxes from php. Code looks like follows

<?php
   $fullAddons=$this->extras->getAdons($cat_id);
   $inads=array();
?>
<div id="addonsholder" class="width_100">
   <?php 
      foreach($fullAddons as $add){
      $sel=in_array($add->id,$inads) ? 'checked="checked"' : '';
      echo '<div class="checkbox"><input '.$sel.' type="checkbox" value="'.$add->id.'" name="add_ons[]" id="adon_'.$add->id.'" /><label for="adon_'.$add->id.'">'.$add->sub_cat_name.'</label></div>';
    }
    ?>
    </div>

I got a div with an error message like following

<div class="error_msg">Please Select Atleast one category</div>

I just want to show this div in "ng-show" if none selected and show form as invalid while submitting the form.

Any one please advice me

Aucun commentaire:

Enregistrer un commentaire