AngularJS - ngrepeat form input elements dynamically filled with default values to post - angularjs

http://jsfiddle.net/9sCnC/12/#
I'm going through a json file and parsing it through ng-repeat, a button on each item opening a modal window.
In this window a form is generated with data I would like to put into another data array which will be send through post to a php file...
<div ng-repeat="value in model.values">
<input type="text" ng-model="model.values[$index]" />
</div>
<hr>
<!--Details content Begin-->
<div class="circle-list">
<div class="circle-list-item" ng-repeat="course in courses | filter:query | orderBy:predicate:reverse | filter:Type" ng-mouseenter="hover(course)" ng-mouseleave="hover(course)">
<span class="btn-xs pull-right">
<span id="Time" class="glyphicon glyphicon-time"></span> {{course.duur}}u
</span>
<a id="course.Id" title="{{course.NoEDA}}" href="{{course.link}}">{{course.titel | lowercase}}</a>
<span id="Type" class="ng-class:course.type">{{course.type}}</span>
<span ng-show="course.showOverlay" class="btn-group btn-group-xs">
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#ModalSubscribe{{$index}}"><span class="glyphicon glyphicon-pencil"></span></button>
<!-- <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-eye-open"></span></button> -->
<!-- Button trigger modal -->
</span>
<div class="modal fade" id="ModalSubscribe{{$index}}" tabindex="-1" role="dialog" aria-labelledby="ModalSubscribe" aria-hidden="true">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="glyphicon glyphicon-pencil"> Inschrijven</h4>
</div>
<div class="modal-body">
<!-- SHOW ERROR/SUCCESS MESSAGES -->
<!--
<div id="messages" ng-show="message" ng-class="{ 'has-error' : errormail }">{{ message }}</div>
-->
<div id="messages" class="alert alert-success" data-ng-show="message" >{{ message }}</div>
<div id="messages" class="alert alert-danger" data-ng-show="errormessage" >{{ errormessage }}</div>
<form id="register" name="register" class="form-horizontal" role="form" ng-submit="processForm()">
<div id="name-group" class="form-group">
<!-- EDA -->
<label class="col-sm-2 control-label">Opleiding:</label>
<div class="col-sm-10 controls">
<input type="text" name="eda[]" class="form-control" value="{{course.NoEDA}}" ng-model="course.NoEDA">
</div>
<!-- Name -->
<label class="col-sm-2 control-label">Naam:</label>
<div class="col-sm-10 controls">
<input type="text" name="name[]" class="form-control" placeholder="Naam" ng-model="formData.name">
</div>
<!-- Matricule -->
<label class="col-sm-2 control-label">Stamnumer:</label>
<div class="col-sm-10 controls">
<input type="number" name="matricule[]" class="form-control" placeholder="Stamnummer" ng-model="formData.matricule">
</div>
</div>
<!--<legend>Email</legend>-->
<div class="form-group" ng-class="{'has-error': errormail}">
<label class="col-sm-2 control-label">Email:</label>
<div class="input-group">
<span class="input-group-addon">#</span>
<input type="email" name="[]mail" class="form-control" data-ng-model="formData.mail" placeholder="mail"/>
</div>
<!--<span class="help-block" ng-show="errormail">{{ errormail }}</span>-->
</div>
<input type="checkbox" ng-model="formData.agree1" name="Agreement1[]" required />
Ik ben akkoord
<input type="checkbox" ng-model="formData.agree2" name="Agreement2[]" required />
Ik ga akkoord
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Sluit</button>
<button type="submit" class="btn btn-primary" ng-enabled="{{register.mail}}"><i class="glyphicon glyphicon-ok"></i> Inschrijven</button>
</div>
</form>
{{ formData }}
</div>
</div>
</div>
<!-- temp, later wel plaatsen
<span class="label label-default">{{course.Departement}}</span>
-->
<small>
<br/><i id="placelabel" class="text-muted"><span class="glyphicon glyphicon-map-marker"></span> {{course.plaats || "-"}}</i>
<i id="placename" class="text-primary"><span class="glyphicon glyphicon-calendar"></span> {{course.organisatie || "-"}}</i>
<small id="public" class="pull-right"><br /><i class="doelgroep">{{course.doelgroep}}</i></small>
</small>
</div>
</div>
<!--Details content End-->
</div>
<!--container content End-->
What I don't understand is:
ng-init="formData.eda=course.NoEDA" is putting the last item in the array I guess
value="{{course.NoEDA}}" this is showing the good item array
how do I transfer the right item from course.NoEDA to another ng-model formData.eda?
I'm just starting with this, if I'm doing this the wrong way please help me out here...
my fiddle isn't working at all but on my local server everything is working except passing the values to post them...
thanks in advance...

Related

ng-show with conditional values gives 2 different issues on same partial [duplicate]

This question already has an answer here:
Angular scope not affecting ng-show as expected
(1 answer)
Closed 7 years ago.
I have the following partial where some expression has
example : ng-show="'{{selectedtournoi.tournois_simple}}'==1"
On the first occurence it provides true evaluation, not on the second one.
I checked my html tags, they sound well formed.
I don't understand this behavior;
full code:
<div Class='' ng-controller="tournoisCtrl">
<div class="">
</div>
<!-- Liste des tournois -->
<div ng-show="showtournoislist">
<div ng-show="tournois.tournois.length" class="">
<ul id="tournois-list">
<li ng-repeat="tournoi in tournois.tournois track by $index">
<div class="tournois">
<div class='row'>
<span class='tournois_title'>{{tournoi.tournois_title}}</span>
</div>
<div class='row'>
<span class='tournois_dates'>Du {{tournoi.tournois_date_debut | date:'d-M-yyyy'}} au {{tournoi.tournois_date_fin | date:'d-M-yyyy'}}</span>
</div>
<div class='row'>
<span class='tournois_dates'> Limite d'inscription : {{tournoi.tournois_date_limite | date:'d-M-yyyy'}}</span>
</div>
<div class='row'>
<a ng-click="toggleshowtournois(tournoi.tournois_id)"><button class="btn btn-primary btn-xs">En savoir plus</button></a>
</div>
</div>
</li>
</ul>
</div>
</div>
<!-- Détail d'un tournoi -->
<div ng-show="!showtournoislist">
<ul class="tournois">
<div>
<span class='tournois_title'>{{selectedtournoi.tournois_title}}</span>
</div>
<div>
<span class='tournois_dates'>Du {{selectedtournoi.tournois_date_debut | date:'d-M-yyyy'}} au {{selectedtournoi.tournois_date_fin | date:'d-M-yyyy'}}</span>
</div>
<div>
<span class='tournois_dates'> Limite d'inscription : {{selectedtournoi.tournois_date_limite | date:'d-M-yyyy'}}</span>
</div>
<div>
<span class='tournois_dates'> Tournoi financé : {{selectedtournoi.tournois_decompte}}</span>
</div>
<div>
<span class='tournois_dates'> Description : {{selectedtournoi.tournois_description}}</span>
</div>
<div>
<a ng-click="showinscris=!showinscris"><button class='badge'>{{selectedinscris.length}} inscris</button></a>
</div>
<!-- Liste des inscrits-->
<div ng-show="showinscris">
<div ng-repeat="tinsc in selectedinscris" class="tournois_dates">
<span class="tournois_inscris_name">{{tinsc.fullname}}</span><br>
<span ng-show="'{{selectedtournoi.tournois_simple}}'==1">Simple ({{tinsc.inscriptions_simple_serie}})</span>
<br ng-show="'{{tinsc.inscriptions_double_partenaire}}'!=''"><span ng-show="'{{tinsc.inscriptions_double_partenaire}}'">Double ({{tinsc.inscriptions_double_serie}})</span>
<span ng-show="'{{tinsc.inscriptions_double_partenaire}}'!=''"> avec {{tinsc.inscriptions_double_partenaire}} / {{tinsc.inscriptions_double_partenaire_club}}</span>
<br ng-show="'{{tinsc.inscriptions_mixte_partenaire}}'!=''"><span ng-show="'{{tinsc.inscriptions_mixte_partenaire}}'">Mixte ({{tinsc.inscriptions_mixte_serie}})</span>
<span ng-show="'{{tinsc.inscriptions_mixte_partenaire}}'!=''">avec {{tinsc.inscriptions_mixte_partenaire}} / {{tinsc.inscriptions_mixte_partenaire_club}}</span>
</div>
</div>
<br>
<div ng-show="!logguedinscris">
<span ng-show="Loggued">
<span ng-show="!showLimite">
<a href ng-show="!showinscription" ng-click="showinscription=!showinscription"><button class="btn btn-primary btn-xs">Participer</button></a>
</span>
</span>
</div>
<div ng-show="!Loggued">
<span ng-show="!showLimite">Vous devez vous <a ui-sref="login">identifier</a> pour participer</span>
</div>
<br>
<!--Mon inscription-->
<div>
<form ng-submit="submitForm()" ng-show='!showLimite'>
<!-- Simple-->
<!-- participation -->
<div class="form-group" ng-show="'{{selectedtournoi.tournois_simple}}'==1">
<label>Simple</label>
<input type="checkbox" name="cbSimple" ng-click="showSi=!showSi" ng-checked="forminscris.inscriptions_simple==1" ng-model="forminscris.inscriptions_simple" >
<!-- Serie -->
<label ng-show="showSi">Serie</label>
<select ng-show="showSi" ng-options="item as item for item in selectedtournoi.tournois_xserie_simple track by item" ng-model="selectedSerieSimple"></select> </div>
<div class="form-group" ng-show="'{{selectedtournoi.tournois_double}}'==1">
<label>Double</label>
<input type="checkbox" name="cbDouble" ng-click="showDbl=!showDbl" ng-checked="forminscris.inscriptions_double==1" ng-model="forminscris.inscriptions_double">
<label ng-show="showDbl">Serie</label>
<select ng-show="showDbl" ng-options="item as item for item in selectedtournoi.tournois_xserie_double track by item" ng-model="selectedSerieDouble"></select>
<br ng-show="showDbl">
<label ng-show="showDbl">Partenaire</label><br ng-show="showDbl">
<label ng-show="showDbl">Bacly ? </label><input type="checkbox" ng-show="showDbl" name="BaclyDbl" ng-checked="showBaclyDbl==true" ng-click="showBaclyDbl=!showBaclyDbl"><br ng-show="showDbl">
<select ng-show="showBaclyDbl && showDbl" ng-model="selectedPartenaireDoubleBacly" ng-options="item.user_id as item.fullname for item in baclyusersdouble.users" class="selectuser"></select>
<input type="text" name="partenaireDouble" ng-show="!showBaclyDbl && showDbl" ng-model="forminscris.inscriptions_double_partenaire">
<br ng-show="showDbl">
<label ng-show="!showBaclyDbl && showDbl">Club :</label><br ng-show="showDbl">
<input type="text" ng-show="!showBaclyDbl && showDbl" name="clubPartenaireDouble" ng-model="forminscris.inscriptions_double_partenaire_club">
</div>
<div class="form-group" ng-show="'{{selectedtournoi.tournois_mixte}}'==1">
<label>Mixte</label>
<input type="checkbox" name="cbMixte" ng-click="showMx=!showMx" ng-checked="forminscris.inscriptions_mixte==1" ng-model="forminscris.inscriptions_mixte">
<!-- <p ng-show="form.userForm.name.$invalid && !form.userForm.name.$pristine" class="help-block">You name is required.</p>-->
<!-- Serie -->
<label ng-show="showMx">Serie</label>
<select ng-show="showMx" ng-options="item as item for item in selectedtournoi.tournois_xserie_mixte track by item" ng-model="selectedSerieMixte"></select>
<br ng-show="showMx">
<label ng-show="showMx">Partenaire</label><br ng-show="showMx">
<label ng-show="showMx">Bacly ? </label><input type="checkbox" name="BaclyMx" ng-checked="showBaclyMx==true" ng-click="showBaclyMx=!showBaclyMx" ng-show="showMx"><br ng-show="showMx">
<select ng-show="showBaclyMx && showMx" ng-model="selectedPartenaireMixteBacly" ng-options="item.user_id as item.fullname for item in baclyusersmixte.users" class="selectuser"></select>
<input type="text" ng-show="!showBaclyMx && showMx" name="partenaireMixte" ng-model="forminscris.inscriptions_mixte_partenaire">
<br ng-show="showMx">
<label ng-show="!showBaclyMx && showMx" >Club :</label><br ng-show="showMx">
<input type="text" ng-show="!showBaclyMx && showMx" name="clubPartenaireMixte" ng-model="forminscris.inscriptions_mixte_partenaire_club">
</div>
<div class="form-group">
<label>Commentaire</label>
<input type="text" name="commentaire" placeholder="" ng-model="forminscris.inscriptions_comment">
</div>
<br>
<div class=''>
<a href ng-click="insertinscription()"><button class="btn btn-primary btn-xs" ng-show="Loggued && !logguedinscris">M'inscrire</button></a>
<a href ng-click="showinscription=!showinscription"><button class="btn btn-info btn-xs" ng-show="!logguedinscris">Annuler</button></a>
<a href ng-click="updateinscription()"><button class="btn btn-primary btn-xs" ng-show="Loggued && logguedinscris" >Mettre à jour</button></a>
<a href ng-click="deleteinscription()"><button class="btn btn-info btn-xs" ng-show="Loggued && logguedinscris" >Me désinscrire</button></a>
</div>
</form>
</div>
</ul>
</div>
</div>
I don't think the interpolation is necessary inside the ng-show directive attribute.
You can use ng-show = " selectedtournoi.tournois_simple == 1 ".
Hope that helps!

Editing Functionality in AngularJS

I am Fairly New to AngularJs, I have done crud operations in AngularJs, I have fetched all the records of user having options like(View, Edit(Update), Delete)
If the User Wants To Update the record then he clicked on edit then shows his/her record. all fields are mandatory. if users deletes the text in the Text-box. then press on cancel button it redirects to mange users page with empty field
Like in my plunker, I want to update one record, Clicked on Edit and then in the name(textbox) make it as blank. Immediately click on Cancel
Then Output will be empty of my record(name field)
But, I want data in user record(name field), if user make it as blank
I was Updated My code in here
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<link href="style.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" rel="stylesheet" />
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Hello Plunker!</h1>
<div class="container" style="padding-top:20px;">
<div ng-app="userApp" data-ng-controller="userController" class="container">
<div ng-show="error" class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<p>{{ error }}</p>
</div>
<div class="modal fade" id="userModel" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
<h4 class="modal-title" id="myModalLabel" ng-hide="editMode">Add User</h4>
<h4 class="modal-title" id="myModalLabel" ng-show="editMode">Edit User</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form" name="adduserform">
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" data-ng-model="user.name" name="name" class="form-control" id="title" placeholder="Your Name" required title="Enter your name" />
</div>
</div>
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Address</label>
<div class="col-sm-10">
<input type="text" data-ng-model="user.address" name="address" class="form-control" id="title" placeholder="Your Address" required title="Enter your address" />
</div>
</div>
<div class="form-group">
<label for="title" class="col-sm-2 control-label">ContactNo</label>
<div class="col-sm-10">
<input type="text" data-ng-model="user.contact" name="contact" class="form-control" id="title" placeholder="Your ContactNo" required title="Enter your contactno" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<span data-ng-hide="editMode">
<input type="submit" value="Add" ng-disabled="adduserform.$invalid" data-ng-click="add()" class="btn btn-primary" />
</span>
<span data-ng-show="editMode">
<!-- <input type="submit" value="Update" ng-disabled="" data-ng-click="update()" class="btn btn-primary"/> -->
<input type="submit" disabled="disabled" value="update" class="btn btn-primary"/>
</span>
<input type="button" value="Cancel" data-ng-click="cancel()" class="btn btn-primary" />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<h1>Users List</h1>
<table class="table table-hover">
<tr>
<th>User ID</th>
<td>Name</td>
<th>Address</th>
<th>Contact No</th>
<th></th>
</tr>
<tr data-ng-repeat="user in users">
<td><strong>{{ user.id }}</strong></td>
<td>
<p>{{ user.name }}</p>
</td>
<td>
<p>{{ user.address }}</p>
</td>
<td>
<p>{{ user.contact }}</p>
</td>
<td>
<p>
<a data-ng-click="get(user)" href="javascript:;">View</a> |
<a data-ng-click="edit(user)" href="javascript:;">Edit</a> |
<a data-ng-click="showconfirm(user)" href="javascript:;">Delete</a>
</p>
</td>
</tr>
</table>
<hr />
<div class="modal fade" id="viewModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
<h4 class="modal-title" id="myModalLabel">View User</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form" name="viewuser">
<div class="form-group">
<label for="Name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
{{user.name}}
</div>
</div>
<div class="form-group">
<label for="Address" class="col-sm-2 control-label">Address</label>
<div class="col-sm-10">
{{user.address}}
</div>
</div>
<div class="form-group">
<label for="ContactNo" class="col-sm-2 control-label">ContactNo</label>
<div class="col-sm-10">
{{user.contact}}
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
<h4 class="modal-title" id="myModalLabel">Confirm Action</h4>
</div>
<div class="modal-body">
Are you sure to delete?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-ng-click="delete()">Ok</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
please help me out with this situation
You are binding your modal to the original user object.
Instead you can make a temporary copy of the user, and if you click cancel, copy the temp back to the original user:
$scope.edit = function () {
$scope.user = this.user;
$scope.tempUser = angular.copy($scope.user); //copy user to temp
$scope.editMode = true;
$('#userModel').modal('show');
};
$scope.cancel = function () {
angular.copy($scope.tempUser, $scope.user); // copy back from temp to user
$('#userModel').modal('hide');
}
See this plunker

UI bootstrap date picker with ng-repeate is not working

I am using angular directive for date picker from UI bootstrap. I also use ng-repeat to add multiple rows. I have added date picker code in ng-repeat. I have displayed these date pickers in bootstrap modal. Also ng-repeat is work fine. But if I add multiple row and click on single calendar icon then all calendar popups of all date picker are shown. I don't know why should this happened. I use is-open="$parent.opened1" to perform click on calendar button. If I use only is-open="opened1" then calendar popoup will open only once (means: can not open after selecting any date). And if I use is-open="$parent.opened1" then after adding multiple rows all calendar popup is open.
Here is my code-
<div class="modal fade bs-example-modal-lg preventiveCarePop" id="preventiveProcess" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<form role="myForm" name="myForm">
<div class="modal-dialog" style="width: 35%;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 style="margin: 0px;">
Preventive Care: <span ng-bind="patientObj.firstName"></span>
<span ng-bind="patientObj.lastName"></span><small
class="newSmall"><span> ({{patientObj.gender}}, <i
class="fa fa-mobile fa-lg"></i>:
{{patientObj.contact.mobileNumber}})
</span></small>
</h4>
</div>
<input type="hidden" ng-model="currentReminder" />
<div class="modal-body">
<div id="divActivites" name="divActivites">
<div class="form-group">
<div class="box-placeholder" ng-repeat="preventive in preventive.preventiveDetailsList">
<div class="form-group">
<div class="row">
<div class="col-lg-4">
<label for="exampleInputEmail1">Start Date<span
style="color: red;">*</span></label>
<p class="input-group">
<input type="text" class="form-control"
datepicker-popup="dd-MM-yyyy"
ng-model="preventive.startOnDate"
is-open="$parent.opened2"
id="dos-{{$index}}"
datepicker-options="dateOptions" close-text="Close"
placeholder="Select Date" required />
<span class="input-group-btn">
<button type="button" class="btn popUpCal"
ng-click="open($event,'opened2')">
<i class="fa fa-calendar"></i>
</button>
</span>
</p>
</div>
<div class="col-lg-4">
<label for="exampleInputEmail1">End Date<span
style="color: red;">*</span></label>
<p class="input-group">
<input type="text" class="form-control"
datepicker-popup="dd-MM-yyyy"
ng-model="preventive.endOnDate"
id="doe-{{$index}}"
is-open="$parent.opened1"
datepicker-options="dateOptions" close-text="Close"
placeholder="Select Date" required />
<span class="input-group-btn">
<button type="button" class="btn popUpCal"
ng-click="open($event,'opened1')" >
<i class="fa fa-calendar"></i>
</button>
</span>
</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-default" ng-click="addDummyPreventive(preventive.preventiveDetailsList,currCaseSheetObjForAddPrv.speciality,preventive.preventiveDetailsList.length)" style="float: right" title="Add new preventive"><i class="fa fa-plus-circle fa-lg"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
Here is my controller
$scope.open = function($event,opened) {
$event.preventDefault();
$event.stopPropagation();
$scope[opened] = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
I don't know what I use to work all fine.
Please share your idea's.
Thanks in advance.
Please see this demo and comments inside code can be helpful.
Html:
<div class="row" ng-repeat="dt in dates">
<div class="col-md-6">
<p class="input-group">
<input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt.date" is-open="dt.opened" datepicker-options="dateOptions" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event,dt)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
JS:
$scope.open = function($event, dt) {
$event.preventDefault();
$event.stopPropagation();
dt.opened = true;
};

Dynamically resize a Bootstrap UI modal when DIV expanded/collapsed

I have the following Bootstrap UI modal template that displays a list of customers in a scrolling DIV.
<div>
<div class="modal-header">
<h3 class="modal-title">Select a customer</h3>
</div>
<div class="modal-body">
<div class="modal-container">
<label data-ng-repeat="cust in customers">
<input name="customer" type="radio" data-ng-value="{{cust}}" value="{{cust}}" data-ng-checked="{{cust}}.name==$parent.selected.item.name" ng-model="$parent.selected.item" />{{cust.name}}<span class="text-muted"> - {{cust.address}}</span>
</label>
</div>
<div class="modal-footer">
<button class="btn btn-success pull-left" data-ng-click="new()">New</button>
<button class="btn btn-primary" data-ng-click="ok()">OK</button>
<button class="btn btn-default" data-ng-click="cancel()">Cancel</button>
</div>
<div id="newCustomer" class="collapse">
<div class="form-group">
<label for="customerName" class="col-sm-5 control-label">Customer Name</label>
<div class="col-sm-5">
<input id="customerName" class="form-control" type="text" data-ng-model="newCustomer.name" placeholder="New customer name" />
</div>
</div>
<div class="form-group">
<label for="customerAddress" class="col-sm-5 control-label">Address</label>
<div class="col-sm-5">
<input id="customerAddress" class="form-control" type="text" data-ng-model="newCustomer.address" placeholder="New customer address" />
</div>
</div>
</div>
</div>
</div>
There are three buttons at the bottom New, OK and Cancel. What I want to happen is when the New button is clicked, the newCustomer div block should be toggled between expanded and collapsed states and importantly to resize the modal so that when expanded the modal will resize to fit the space taken up by the div block, and also to shrink the modal when the div block is collapsed.
Can this be done using a pure Bootstrap and AngularJS solution?
I am using Bootstrap v3.3.1 and AngularJS v1.3.9.
What I'd do is to actually use bootstrap collapse within your modal. This way you'd have everything done with boostrap.
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<label data-ng-repeat="cust in customers">
<input name="customer" type="radio" data-ng-value="{{cust}}" value="{{cust}}" data-ng-checked="{{cust}}.name==$parent.selected.item.name" ng-model="$parent.selected.item" />{{cust.name}}<span class="text-muted"> - {{cust.address}}</span>
</label>
<div class="collapse" id="collapseExample">
<div class="well">
<div class="form-group">
<label for="customerName" class="col-sm-5 control-label">Customer Name</label>
<div class="col-sm-5">
<input id="customerName" class="form-control" type="text" data-ng-model="newCustomer.name" placeholder="New customer name" />
</div>
</div>
<div class="form-group">
<label for="customerAddress" class="col-sm-5 control-label">Address</label>
<div class="col-sm-5">
<input id="customerAddress" class="form-control" type="text" data-ng-model="newCustomer.address" placeholder="New customer address" />
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-success" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
NEW BUTTON
</button>
<button class="btn btn-primary" data-ng-click="ok()">OK</button>
<button class="btn btn-default" data-ng-click="cancel()">Cancel</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
http://jsfiddle.net/tea6gj4e/1/

Changes are not applying to AngularJS view file

I am using AngularJS as my front-end, below is my HTML file
<div >
<div class="modal-dialog ">
<div class="modal-content">
<div class="modal-body">
<div style="margin-bottom: 10px;">
<button type="button" ng-click='cancel()' class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">{{alert.summary}}</h4>
</div>
<form name="alertForm" novalidate>
<div ng-if="!displayMap">
<alert ng-if='displayAlertMsg' type="alertMsg.type">{{alertMsg.message}}</alert>
<input type="hidden" ng-model="alert.source" />
<div class="field-box">
<span class="checkboxLabel">Public: </span><input type="checkbox" id='updateType' ng-true-value="1" ng-false-value="0" ng-model="alert.publicAlert"></input>
</div>
<div class="field-box">
<label>qweqwName:</label>
<input class="span5" id='updateName' ng-model="alert.summary" required />
</div>
<div class="field-box">
<label>Notes:</label>
<textarea id='updateNotes' ng-model="alert.details" rows="2" required ></textarea>
</div>
<div class="span3" style="margin-left: 0px;">
<div class="field-box">
<label>Priority:</label>
<select ng-model="updatePriority" ng-options="p.name for p in priorities" ng-change='updateP(updatePriority)'></select>
</div>
<div class="field-box">
<label>Status:</label>
<select ng-model="updateState" ng-options="s.name for s in statusList" ng-change="updateS(updateState)"></select>
</div>
</div>
</div>
<div id="alertmap-buttons" class="span2 no-margin">
<button id="alert-add-location" class="btn btn-default pull-left" ng-click="displayMap = !displayMap"><span ng-if="!displayMap">Add Location</span><span ng-if="displayMap">Done</span></button>
<button id="alert-cancel-location" class="btn btn-danger" ng-if="displayMap">Cancel</button>
</div>
<div id="latlng-label" class='span3 pull-right no-margin'>
<div class="pull-left"><label class="latlng-label">lat: {{alert.latitude}}</label></div>
<div class="pull-right"><label class="latlng-label">long: {{alert.longitude}}</label></div>
</div>
<!--Select Coords from map-->
<!--Google Map Directive-->
<div ng-init="displayMap = false" ng-if="displayMap">
<google-map class="create-alert-map angular-google-map-container" center="map.center" zoom="map.zoom"
draggable='true'
events="mapEvents">
<markers models="themarkers"
coords="'self'"
>
</markers>
</google-map>
</div>
<!--Lat and Long
<input placeholder="Latitude" class="span2" id='updateLat' ng-model="alert.latitude" />
<input style="float: right" placeholder="Longitude" class="span2" id='updateLong' ng-model="alert.longitude" /-->
</form>
</div>
<div ng-if="!displayMap" class="modal-footer">
<button type="button" class="btn btn-default" ng-click="submit()" ng-disabled="alertForm.$invalid">Save</button>
<button type="button" class="btn btn-default" ng-click="cancel()">Close</button>
</div>
</div>
</div>
This file is given to me by client and he want some CSS changes etc in that. But when I try to edit the file nothing is happening to the modal dialog box, for example if I change button text from Save to Submit it's not applying in the file. How come this???
If this information is not enough I can give controller JS file also. Thanks..

Resources