I am trying to get datepickers to display in a table using an ng-repeat. I have a begin date and end date. When I try to display both datepickers they display one over the other. Below is my code and a screenshot of what is happening.
<table datatable="ng" dt-options="dtOptions" dt-columns="dtColumns" class="table table-bordered">
<tbody>
<tr ng-repeat="waiver in model.waivers" >
<td class="input-group">
<input class="form-control" type="text" datepicker-popup="MM/dd/yyyy" ng-model="waiver.StartDate" is-open="waiver.isOpen" close-text="Close" />
<span class="input-group-btn">
<button class="btn btn-default" ng-click="open($event, waiver)"><i class="fa fa-calendar"></i></button>
</span>
</td>
<td class="input-group">
<input class="form-control" type="text" datepicker-popup="MM/dd/yyyy" ng-model="waiver.EndDate" is-open="waiver.isOpen" close-text="Close" />
<span class="input-group-btn">
<button class="btn btn-default" ng-click="open($event, waiver)"><i class="fa fa-calendar"></i></button>
</span>
</td>
<td><input type="text" ng-model="waiver.FuelCap" /></td>
<td><button type="button" ng-click="updateWaiver(waiver)" class="btn btn-warning"><i class="fa fa-refresh"></i></button></td>
<td><button type="button" ng-click="removeWaiver(waiver)" class="btn btn-danger"><i class="fa fa-trash-o"></i></button></td>
</tr>
</tbody>
</table>
Screenshot
Here is a quick plunkr example.
I know they are both opening when the open button is clicked but if you could help explain why they appear in the same column of the table.
It has to do with how bootstrap is styling the input-group. You need to not place that class on the td. Try moving it down a level like so:
<td>
<div class="input-group">
<input class="form-control" type="text" datepicker-popup="MM/dd/yyyy" ng-model="waiver.StartDate" is-open="waiver.isOpen" close-text="Close" />
<span class="input-group-btn">
<button class="btn btn-default" ng-click="open($event, waiver)">open</button>
</span>
</div>
</td>
<td>
<div class="input-group">
<input class="form-control" type="text" datepicker-popup="MM/dd/yyyy" ng-model="waiver.EndDate" is-open="waiver.isOpen" close-text="Close" />
<span class="input-group-btn">
<button class="btn btn-default" ng-click="open($event, waiver)">open</button>
</span>
</div>
</td>
Related
I have seen this plunker it is very nice but here we can not pass the language code.
<!doctype html>
Selected date is: {{dt | date:'fullDate' }}
<div class="well well-small pull-left" ng-model="dt">
<datepicker min="minDate" show-weeks="showWeeks"></datepicker>
</div>
<div class="form-horizontal">
<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" />
<button class="btn" ng-click="open()"><i class="icon-calendar"></i></button>
</div>
<hr />
<button class="btn btn-small btn-inverse" ng-click="today()">Today</button>
<button class="btn btn-small btn-inverse" ng-click="dt = '2009-08-24'">2009-08-24</button>
<button class="btn btn-small btn-success" ng-click="toggleWeeks()" tooltip="For inline datepicker">Toggle Weeks</button>
<button class="btn btn-small btn-danger" ng-click="clear()">Clear</button>
<button class="btn btn-small" ng-click="toggleMin()" tooltip="After today restriction">Min date</button>
I have form with input fields, radio buttons, select boxes. Need submit button make active after when all fields have a data.
example my fields and button.
<div class="form-group" ng-class="{ 'has-error': myForm.birth.$touched && myForm.birth.$invalid }">
<label class="col-sm-3 control-label">{{getWord('Dob')}}<sup>*</sup></label>
<div class="col-sm-6">
<p class="input-group">
<input type="text" placeholder="1988-12-12" class="form-control" name="birth"
uib-datepicker-popup="{{format}}" ng-model="patient.DOB"
data-placeholder=""
is-open="isOpened" datepicker-options="dpOptions"
close-text="Close" alt-input-formats="altInputFormats" required/>
<span class="input-group-btn">
<button type="button" class="btn btn-default"
ng-click="openCalender()"><i
class="glyphicon glyphicon-calendar"></i>
</button>
</span>
<p ng-show="myForm.birth.$error.required" style="color:red" ng-if="myForm.birth.$touched">Date of birth is
required.</p>
</p>
</div>
</div>
and code button
<div class="form-group">
<div class="text-center">
<button class="btn btn-labeled btn-success" type="button" ng-click="makeAptmn()">
<span class="btn-label"><i class="glyphicon glyphicon-ok"></i></span>
{{getWord('makebutton')}}
</button>
<button class="btn btn-labeled btn-danger" type="button">
<span class="btn-label"><i class="glyphicon glyphicon-remove"></i></span>
{{getWord('clearbutton')}}
</button>
</div>
</div>
and need same for clear button, clear all input fields.
Just modify your button code as:
<button class="btn btn-labeled btn-success" type="button" ng-click="makeAptmn()"
ng-disabled="myForm.$invalid">
<span class="btn-label"><i class="glyphicon glyphicon-ok"></i></span>
{{getWord('makebutton')}}
</button>
I added ng-disabled="myForm.$invalid" which will disable the button when the any of the input field is not valid.
I am new to Laravel and Angularjs. I would like some help on how to go about this.
Angular controller function
var loadTables = function(){
tableService.all(1,20)
.success(function(response){
console.log(response);
$scope.tables = response.data;
$scope.towns=response.town;
$scope.countrys=response.country;
$scope.package_lists=response.package_list;
$scope.categories=response.categories;
Laravel
$id = Auth::user()->id;
$packages = User::find($id)->packages;
//$packages=$packages->paginate(Input::get('perPage'))->toArray();
$countries = Country::lists('name', 'id');
$towns = Town::lists('name', 'id');
$categories = Category::lists('name', 'id');
$package_list=$packages->lists('name','id');
$packages->load('country');
return (['data'=>$packages,'town'=>$towns, 'categories'=>$categories, 'package_list'=>$package_list]);
View
<option ng-repeat="country in countrys" value="#{{country.id}}">#{{country.name}}</option>
1.The country values are not displayed in the view. how do i go about this.
<div ng-controller="tableController">
<a class="add-link btn btn-success" ng-click="toggleForm()" ng- hide="showForm">Add Packages</a>
<table class="table table-striped breathe" ng-hide="showForm">
<thead>
<tr><th>Name</th><th>About</th><th>status</th><th>Image</th> <th>Action</th></tr>
</thead>
<tbody>
<tr ng-repeat="table in tables">
<td>#{{table.name}}</td>
<td>#{{table.short_description}}</td>
<td>#{{table.status}}</td>
<td><img width="120" heigth="72" ng- src="#{{getImageSource(table.image)}}"/></td>
<td>
<button class="btn btn-sm btn-warning" ng- click="editTable(table.id)">Edit</button>
<button class="btn btn-sm btn-danger" ng- click="deleteTable(table.id, currentPage, $index)">Delete</button>
</td></tr>
</tbody>
</table>
<ul class="pagination" ng-hide="showForm">
<li ng-class="{'disabled':currentPage==1}"><a ng- click="loadFirstPage()">«</a></li>
<li ng-repeat="page in pages" ng-class="{'active':page==currentPage}"><a ng-click="loadNthPage(page)">#{{page}}</a></li>
<li ng-class="{'disabled':currentPage==lastPage}"><a ng-click="loadLastPage()">»</a></li>
</ul>
<form name="tablesForm" ng-show="showForm" class="col-md-4" enctype="multipart/form-data">
<div class="form-group">
Name<input type="text" name="number" ng-model="newName" class="form- control" required>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
Avarage Price<input type="text" name="seats" ng-model="newPrice" class="form-control" required>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
Short Description<input type="text" name="position" ng- model="newShort_description" class="form-control">
</div>
<div class="form-group">
Description<input type="textarea" name="description" ng-model="newDescription" class="form-control">
</div>
<div class="form-group">
Category<select type="text" id="category" ng-model="newCategory" class="form-control" required>
<option ng-repeat="category in categories" value="#{{category.id}}">#{{category.id}}</option>
</select>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
Country<select type="text" name="country" ng-model="newCountry" class="form-control" required>
<option ng-repeat="country in countrys" value="#{{country.id}}">#{{country.name}}</option>
</select>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
Town<select type="text" name="town" ng-model="newTown" class="form-control" required>
<option ng-repeat="town in towns" value="#{{town.id}}">#{{town.name}}</option>
</select>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
<img width="120" height="82" ng-src="#{{newThumbnail}}" ng-show="showEdit" style="display: block;" />
Image<input type="file" name="thumbnail" ng-file-select="onFileSelect($files)">
</div>
<div class="form-group">
<button class="btn btn-primary" ng-hide="showEdit" ng-click="tablesForm.$valid &&addNewTable(newNumber,newSeats,newPosition,newDescription,newAvailable, currentPage)">Add new table</button>
<button class="btn btn-primary" ng-show="showEdit" ng-click="tablesForm.$valid && updateTable(tableId, newNumber,newSeats,newPosition,newDescription,newAvailable)">Update table</button>
<button class="btn btn-danger" ng-show="showForm" ng-click="toggleForm()">Cancel</button>
</div>
You're not returning countries on the response list
Try the below code:
return (['data'=>$packages,'town'=>$towns, 'country':$countries, 'categories'=>$categories, 'package_list'=>$package_list]);
Edit: as per your comments, it shows that you're returning your data as objects, not arrays. For Angular to iterate through that data, it should be stored in an array.
I would have a question concerning variables in scope and visibility.
Currently I have two controller variables:
vm.selectedUser
vm.selectedUserRole
The problem is, that I generate the tables in a ng-repeat loop and all inputs and selects in the different tables share this two mentioned variables above.
My question now would be how can I use this two parameters above in my method:
vm.addInstitutionUserConnection(institutionUserConnectionContent.institution, institutionUserConnectionContent, selectedUser, selectedUserRole)
Is there any chance to do this because the input, select elements and the span-button element (add user) have different scopes (this is my guess - I don't know exactly)
Thanks a lot for help!
<div ng-repeat="institutionUserConnectionsOfInstitution in vm.institutionUserConnectionsOfInstitutions">
<div ng-repeat="institutionUserConnectionContent in institutionUserConnectionsOfInstitution.institutionUserConnectionContents">
<div ng-show="addUser" class="row">
<table>
<tr>
<td class="adduserinput">
<input
type="text"
class="form-control"
placeholder="Benutzer durchsuchen"
ng-model="vm.selectedUser"
typeahead="user as vm.userLabelFormatter(user) for user in vm.getUsersByTerm($viewValue) | limitTo:5"
typeahead-min-length="3"
typeahead-wait-ms="100"
typeahead-editable="false" />
</td>
<td class="adduserroles">
<select class="form-control" ng-model="vm.selectedUserRole" ng-options="role as role for role in vm.roles">
</select>
</td>
<td>
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="vm.addInstitutionUserConnection(institutionUserConnectionContent.institution, institutionUserConnectionContent)">add user</button>
</span>
</td>
</tr>
</table>
</div>
</div>
Do it like this -
<div ng-repeat="institutionUserConnectionsOfInstitution in vm.institutionUserConnectionsOfInstitutions">
<div ng-repeat="institutionUserConnectionContent in institutionUserConnectionsOfInstitution.institutionUserConnectionContents">
<div ng-show="addUser" class="row">
<table>
<tr>
<td class="adduserinput">
<input
type="text"
class="form-control"
placeholder="Benutzer durchsuchen"
ng-model="institutionUserConnectionContent.selectedUser"
typeahead="user as vm.userLabelFormatter(user) for user in vm.getUsersByTerm($viewValue) | limitTo:5"
typeahead-min-length="3"
typeahead-wait-ms="100"
typeahead-editable="false" />
</td>
<td class="adduserroles">
<select class="form-control" ng-model="institutionUserConnectionContent.selectedUserRole" ng-options="role as role for role in vm.roles">
</select>
</td>
<td>
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="vm.addInstitutionUserConnection(institutionUserConnectionContent.institution, institutionUserConnectionContent, institutionUserConnectionContent.selectedUser, institutionUserConnectionContent.selectedUserRole)">add user</button>
</span>
</td>
</tr>
</table>
</div>
</div>
Explanation -
I just changed the vm to institutionUserConnectionContent.
reason - since you'll have multiple rows in the table (ng-repeat), if you use vm, you would end up with overwriting the same selectedUser and selectedUser of one row with other.
Hope this helps.
I am building a table using angular ng-repeat. I need to have the ability to update or delete each row independently and thus need to validate each row independently.
<tr ng-repeat="item in model.items" >
<td><input type="text" ng-model="item.AccountNumber" ng-maxlength="model.validation.maxAccountLength" /></td>
<td><select ng-model="item.OriginCountry" ng-options="country.Id as country.Name for country in model.OriginCountries"></select></td>
<td><select ng-model="item.DestinationCountry" ng-options="country.Id as country.Name for country in model.DestinationCountries"></select></td>
<td><input type="text" ng-model="item.Zone" ng-maxlength="4" /></td>
<td><button type="button" ng-click="updateItem(item)" class="btn btn-warning" ><i class="fa fa-refresh"></i></button></td>
<td><button type="button" ng-click="removeItem(item)" class="btn btn-danger"><i class="fa fa-trash-o"></i></button></td>
</tr>
Is it possible to validate each row idependently
Try to wrap the row contents with forms and add name attributes to your inputs/selects
<tr ng-repeat="item in model.items" >
<td>
<form name="form">
<input name="account_number" type="text" ng-model="item.AccountNumber" ng-maxlength="model.validation.maxAccountLength" /></td>
<td>name="origin" ng-model="item.OriginCountry" ng-options="country.Id as country.Name for country in model.OriginCountries"></select></td>
<td><select name="destination" ng-model="item.DestinationCountry" ng-options="country.Id as country.Name for country in model.DestinationCountries"></select></td>
<td><input name="zone" type="text" ng-model="item.Zone" ng-maxlength="4" /></td>
<td><button type="button" ng-click="updateItem(item)" class="btn btn-warning" ><i class="fa fa-refresh"></i></button></td>
<td><button type="button" ng-click="removeItem(item)" class="btn btn-danger"><i class="fa fa-trash-o"></i></button>
</form>
</td>
</tr>
Now you can use the FormController state like form.$submitted or form.zone.$touched
(https://docs.angularjs.org/guide/forms)