How do I add a ng-click event to a bootstrap glyphicon in a textbox? The event doesn't get fired...
<body ng-app ng-init="mymodel='THIS IS MY MODEL'">
<h3>How to clear the model on remove icon click?</h3>
<div class="container">
<div class="form-group has-feedback" >
<input type="text" class="form-control" ng-model="mymodel"/>
<i class="glyphicon glyphicon-remove form-control-feedback"
ng-show="mymodel" ng-click="mymodel = null"></i>
</div>
<p>This is my model: {{mymodel}}</p>
<strong ng-click="mymodel = null">This works tho...</strong>
</div>
</body>
Plnkr link
This is happening because glyphicons provided with " pointer-events: none;" as default you can override it and remove this functionality by simple CSS:-)
.my .glyphicon {
pointer-events: all;
}
<div class="form-group has-feedback my" >
<input type="text" class="form-control" ng-model="mymodel"/>
<i class="glyphicon glyphicon-remove form-control-feedback"
ng-show="mymodel" ng-click="mymodel = null"></i>
</div>
Plunker
Related
I am completely new to angular JS. I have a form with a keyword input box. I need to add auto-complete feature to this input box using angularJS md-autocomplete. My existing html code is as shown below:
Output with input tag
<div class="container formHolder" ng-controller="AppController as ctrl">
<form class="form-horizontal" name="myForm" novalidate>
<h4 class="page-header" style="text-align: center;"><b>Keyword Search</b></h4>
<div class="form-group row" style="padding-left: 2%;padding-right:2%; padding-top: 3%;">
<label for="keyword" class="control-label col-sm-3 labels">Keyword <sup style="color: red">*</sup></label>
<div class="col-sm-9">
<input type="text" ng-class="{errorBorder: myForm.keyword_name.$touched && myForm.keyword_name.$invalid}" class="form-control" ng-model="keyword_name" ng-keyup="total(keyword_name)" name="keyword_name" id="keyword" placeholder="Enter Keyword" required>
<!-- Md auto complete to be attached to this input here -->
</div>
</div>
<div class="form-group row" style="padding-left: 2%;padding-right:2%; padding-bottom: 3%">
<div class="col-sm-9">
<button type="submit" ng-disabled="myForm.$invalid" class="btn btn-primary justify-content-center align-content-between" style="margin-right: 10px"><i class="material-icons" style="vertical-align:middle;">search</i>Search</button>
</div>
</div>
</form>
</div>
I want to add auto-complete using AngularJS, so I used md-autocomplete as shown in the code snippet below.
Output with md-autocomplete tag
<div class="container formHolder" ng-controller="AppController as ctrl">
<form class="form-horizontal" name="myForm">
<h4 class="page-header" style="text-align: center;"><b>Keyword Search</b></h4>
<div class="form-group row" style="padding-left: 2%;padding-right:2%; padding-top: 3%;">
<label for="keyword" class="control-label col-sm-3 labels">Keyword <sup style="color: red">*</sup></label>
<div class="col-sm-9">
<!-- Md auto complete to be attached to this input here -->
<md-autocomplete
md-input-name="keyword"
md-selected-item="ctrl.selectedItem"
md-search-text-change="ctrl.searchTextChange(ctrl.searchText)"
md-search-text="ctrl.searchText"
md-selected-item-change="ctrl.selectedItemChange(item)"
md-items="item in ctrl.querySearch(ctrl.searchText)"
md-item-text="item.display"
md-min-length="1"
placeholder="Keyword Search">
<md-item-template>
<span md-highlight-text="ctrl.searchText" md-highlight-flags="^i">{{item}}</span>
</md-item-template>
</md-autocomplete>
</div>
</div>
<div class="form-group row" style="padding-left: 2%;padding-right:2%; padding-bottom: 3%">
<div class="col-sm-9">
<button type="submit" ng-disabled="myForm.$invalid" class="btn btn-primary justify-content-center align-content-between" style="margin-right: 10px"><i class="material-icons" style="vertical-align:middle;">search</i>Search</button>
</div>
</div>
</form>
</div>
But this replacement changes the style of my input box. I want my input box to be like the one shown in the first image. So is there a way to retain my input box and add autocomplete to it, so that the style remains unchanged. Or is there a way by which I can style my md-autocomplete element to look as in the first image?
Please help me on this.
I am using md-datepicker from angular material. It is working fine except on bootstrap modal. I have applied various solutions like z-index:1200 but none of them proves useful for me.
Following libraries I am using:
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.1.10/angular-material.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.1.10/angular-material.min.css" />
It shows the area when I use inspect element:
Here is the Modal Code:
<!-- Bootstrap Modal for Add an Event -->
<div class="modal fade" id="AddEvent" role="dialog">
<div class="modal-dialog">
<form ng-submit="addNewEvent()">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"> <span class="team-member-icon"><img class="" ng-src="home/img/event-star.svg"></span> Add Event</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<div class="add-member-modl">
<div class="form-group">
<label>Event Name</label>
<input ng-model="newEvent.name" type="text" ng-focus="focusInput = true" class="form-control" placeholder="Mehndi" ng-required="true">
<input type="hidden" ng-model="newEvent.event_id">
<ul class="advance_search_inner" ng-show="focusInput">
<li ng-repeat="event in events| filter:newEvent.name" ng-click="newEvent.name = event.name; focusInput = false; newEvent.event_id = event._id">
{{event.name}}
</li>
</ul>
</div>
<div class="form-group">
<label>Date</label>
<md-datepicker md-open-on-focus ng-model="newEvent.start_date"></md-datepicker>
</div>
<div class="form-group">
<label>Duration</label>
<select class="form-control" ng-model="newEvent.duration">
<option value="1 Day">1 Day</option>
<option value="2 Days">2 Days</option>
<option value="3 Days">3 Days</option>
</select>
<!--<input type="text" class="form-control" ng-model="newEvent.duration" placeholder="1 Day(s)" ng-required="true">-->
</div>
</div>
</div>
<div class="modal-footer mod-footr">
<button type="submit" class="btn btn-default">Send</button>
</div>
</div>
</form>
</div>
</div>
Probably the z-index of the modal is higher than the date picker selector. Try to change the datepicker z-index with the following css:
.md-datepicker-calendar-pane {
z-index: 2000;
}
I'm doing a system to idle a user after 1 minute and I'm opening a modal with a button to alert the user with a button inside which redirects to login page.
controllerScope.logout = function () {
alert("logout");
$location.path('/');
AuthService.logout(controllerScope.user).then(function (result) {
$state.go('user.signin');
});
};
In my view:
<script type="text/ng-template" id="timedout-dialog.html">
<div class="modal-header">
<h3>Oh, Snap! You've Timed Out!</h3>
</div>
<div class="modal-body">
<p>
You were idle too long. Click the button below to be redirected to the login page and begin again.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger btn-small" ng-click="doLogout()">Back To Login</button>
</div>
</script>
Why when I click on my "back to login" on modal it doesn't go to my function on the controller? I tried to pop up an alert, a simple thing but event that doesn't work
You need to make below changes, since you use controller as syntax :
In controller it should be like var controllerScope = this
In HTML controller declaration be like : ng-controller ="yourcontrollername as controllerScope"
During calling logout, it should be like ng-click="controllerScope.logout()"
Update
Your plunker has many issues, this even doesn't run angular.
So I created this Fiddle with minimal possible code to show the things to be done.
In general :
use controller as alias., for logout ng-click="inventoryCtrl.openNewDeviceModal()" and for opening modal popup use alias as well controller: 'InventoryController as inventoryCtrl',
You set doLogout() function into your ng-click. Would you mean logout() as in your controller ?
Your ng-click method is wrongly called: Kindly change ng-click="controllerScope.logout()"> instead of ng-click="doLogout()">
Update
I have uploaded my code to share with you https://jsfiddle.net/y0xrgjaf/
Your template code in outside of the controller div tag. You should add your all html code inside of the main div
<div ng-controller="controllername">
//all code should be here
</div>
Copy this below code and paste it
<div class="row" ng-controller="InventoryController as inventoryCtrl" >
<div class="col-md-12">
<div class="panel mb25">
<div class="panel-body">
<table class="table mb0 table-striped datatable" ui-jq="dataTable" ui-options="devicesData">
<thead>
<tr>
<th></th>
<th>S/N</th>
<th>IP</th>
<th>Name</th>
<th>Manufacturer</th>
<th>Model</th>
<th>Organization</th>
<th style="width:70px;"></th>
</tr>
</thead>
</table>
</div>
</div>
<div>
<button class="btn btn-default" ng-click="openNewDeviceModal()">Add Device</button>
</div>
</div>
<script type="text/ng-template" id="newDeviceModalContent.html">
<div class="modal-header">
<h3 class="modal-title" ng-bind="deviceModalTitle"> Add Device</h3>
</div>
<div class="modal-body">
<form class="form-horizontal bordered-group" role="form" name="addDeviceForm">
<div class="form-group">
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" ng-model="newdevice.data.name" required>
<span ng-show="addDeviceForm.name.$invalid">The name is required.</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">S/N</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="sn" ng-model="newdevice.data.sn" required>
<span ng-show="addDeviceForm.sn.$invalid">The S/N is required.</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Model</label>
<div class="col-sm-10">
<select class="form-control" ng-model="newdevice.device_type_id" ng-options="type.id as type.model for type in deviceTypes">
<option value="">None</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Organization</label>
<div class="col-sm-10">
<select class="form-control" ng-model="newdevice.organization_id" ng-options="organization.id as organization.data.name for organization in organizations">
<option value="">None</option>
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-default btn-sm" ng-click="saveDevice()" ng-disabled="addDeviceForm.name.$invalid || addDeviceForm.sn.$invalid">Save</button>
<button class="btn btn-default btn-sm" ng-click="cancel()">Cancel</button>
</div>
</script>
<script type="text/ng-template" id="timedout-dialog.html">
<div class="modal-header">
<h3>Oh, Snap! You've Timed Out!</h3>
</div>
<div class="modal-body">
<p>
You were idle too long. Click the button below to be redirected to the login page and begin again.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger btn-small" ng-click="inventoryCtrl.logout()">Back To Login</button>
</div>
</script>
</div>
I want to show the div which has Turn On E-Verify when clienId has a value if not I want to show the div which has Turn Off E-verify. I am not getting any errors but always the second div shows up and the button won't work. What am I doing wrong?
HTML :
<div class="col-md-12 col-centered" ng-app="CompanyEVerify">
<div class="row" ng-controller="EVerifyOptionController">
<form name="EverifyForm" id="EVerifyForm" class="form-horizontal" role="form" novalidate ng-submit="EVerifyForm.$valid && submit()"
style="background-color: #F0F0F0; border-radius: 8px; padding-top: 10px; margin: 15px !important;">
<div class="alert alert-danger" id="messages" style="display:none">{{message}}</div>
<div class="form-horizontal">
<input type="hidden" ng-model="company.Id" />
<div class="row">
<div class="col-md-12">
<div style="font-size:20px;font-weight:bold;display:inline-block">Would you like to opt for E-Verify feature?</div>
<br />
<div >
<div class="row" ng-if="clientId">
<div class="col-xs-12 form-group">
<label class="control-label col-xs-2">Client ID</label>
<div class="col-xs-7">
<input type="text" name="clientID" class="form-control input-md" ng-model="clientID" />
</div>
<button type="button" class="btn btn-success col-xs-3" ng-click="saveEverifyOption(clientID)">
<i class="fa fa-spinner fa-pulse"></i> Turn On E-Verify
</button>
</div>
</div>
<div class="row" ng-if="!clientId">
<div class="col-xs-12 form-group">
<label class="control-label col-xs-2">Client ID</label>
<div class="col-xs-7">
<input type="text" name="clientID" class="form-control input-md" ng-model="clientID" />
</div>
<button type="button" class="btn btn-danger col-xs-3" ng-click="saveEverifyOption(clientID)">
<i class="fa fa-spinner fa-pulse"></i> Turn Off E-Verify
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
In my controller :
$scope.clientId= sessionStorage.clientId;
I am going to assume that your controller is properly evaluating your conditions. In which case you would use ng-class to bind to css classes. I am not sure If you are trying to hide/show or disable toggle. Going with show/hide, you can make a class:
.hide{
display:none;
}
On one of your elements:
<button ng-class="{'hide': clientId}" ></button>
On the other element:
<button ng-class="{'hide': !clientId}" ></button>
Now the hide property on both elements is bound to one single source.
Check out docs example
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;
};