How to simulate dropdown list with input? - angularjs

I have this part of code :
http://jsfiddle.net/Lt7aP/1015/
What I`m trying to do is when user click on that input or on button next to it I want to expand list but problem is that i cant get list below that input. Any suggestion?
<div class="input-group-btn">
<button type="button" data-toggle="dropdown">
<input class="input-sm-custom bg-light-black white bold fs15" readonly="readonly" style="border:1px solid #1d1d1d;width: 100%;font-weight: bold;" data-ng-model="selectedItem" ng-model-options="{ debounce: 500 }">
</button>
<button type="button" class="bg-light-black dropdown-toggle input-sm-custom mr2 fs14 bt-light-black" data-toggle="dropdown"><span class="carret-arrow white "></span></button>
<ul id="color-dropdown-menu" class="dropdown-menu dropdown-menu-list bg-light-black" role="menu" style="width: 100%;font-weight: bold;" ng-repeat="item in OddsRepresentations">
<li class="pointer padding2 fs15" ng-model="selectedItem" >{{item}}</li>
</ul>
</div>
It work like this:
<div class="select-wrapper">
<select class="form-control" data-ng-model="selectedItem" data-ng-options="item as item for item in OddsRepresentations" data-ng-change="changeOddsRepresentation()"></select>
</div>
But i want to make my own dropdown to be same at all browser

I have made few changes in your code to have a working dropdown. First of all I've set a boolean to show or not the list.
This is done by adding ng-click="isOpen = !isOpen" in your button. And then your ul will be like this :
<ul id="color-dropdown-menu" class="dropdown-menu dropdown-menu-list bg-light-black" role="menu" style="width: 100%;font-weight: bold;" ng->
<li class="pointer padding2 fs15" ng-if="isOpen" ng-repeat="item in OddsRepresentation" >
<span ng-click="select(item);" ng-bind="item"></span></li>
</ul>
Notice, that there is also an ng-click on your li, it's for save you value and then print it on your input.
Working Fiddle

Related

Uib accordion toggle issue

I am using uibAccordion where the toggling is not happening properly,
If I click 1st repeated element all others also opening. Below is the code.
<ul>
<li ng-repeat="(key, value) in scenariosViewAll.collectionBookObject">
<div class="desc">
<uib-accordion close-others="true" class="">
<div uib-accordion-group id="{{$index+1}}" class="panel-default" is-open="status.open" is-disabled="true" prevent-click="false" ng-init="status.open = (key == scenariosViewAll.shared.currentSelectedAccordion) ? true : false" ng-class="{'opened': status.open}" ng-if="value.length > 0">
<uib-accordion-heading>
<span class="accordion-toggle-wrapper">
<span class="accordion-title">
{{key}}
</span>
<span class="pull-right acc-icon-set">
<span class="collection-indicator">{{value.length}}</span>
<span class="arrow-toggle">
<button class="btn btn-icon" aria-hidden="true" ng-click="status.open = !status.open;">
<i class="icon" ng-class="{'icon-chevron-up': status.open, 'icon-chevron-down': !status.open}"></i>
</button>
</span>
</span>
</span>
</uib-accordion-heading>
</div>
</uib-accordion>
</div>
</li>
</ul>
I have tried passing id as {{index+1}} and also close-others="true".
But it's not working
Here
ng-init="status.open = (key == scenariosViewAll.shared.currentSelectedAccordion) ? true : false"
I really don't know what you are binding status.open to, but clearly this is wrong and really ambiguous
Simplify it, and give is-open a property that refers to a different value for each iterated key/value, for example
ng-init="value.ui.isOpen = false;"
is-open="value.ui.isOpen"
If you are raelly lazy, and don't need to access these variables inside your controller, just don't bind it to anything
ng-init="isOpen = false;" // by now this is redundant and can be removed
is-open="isOpen"
this will work because ngRepeat created a new scope for every iteration it goes, so a new isOpen will be created per such scope.
I got solution by passing index:
<div uib-accordion-group class="panel-default" ng-init="status.open = false;" is-open="status.open[$index]" prevent-click="false" ng-class="{'opened': status.open}" ng-if="value.length > 0">

Hide previous content on second click of the button of any loop inside ng repeat

I have a ng-show inside ng repeat. Whenever i click the comment button it shows the div tag contains comment box which shows previous comments of that list.
The actual problem is when i click one comment button, it shows comment box with contents but when i click the another comment button, comment box with contents will be shown but it also changes the contents of previous comment box also (i mean showallcomments which is over-writing every time when i click on comment button).
Note: In more simple words the problem is- On clicking comment button , the previously opened comment box by clicking comment button doesnt close
Note: Comment box is not a model which doesn't popup
So my solution is whenever i click the second comment button, it should hide all previous comment box.(I need to hide the all previously opened comment box when i click comment button each time)
How can i do this? can anyone help me out
I think u may understand the question if you look my code.
My code is,
<div class="col-lg-12" ng-repeat="dat in details | orderBy : sortColumn : reverseSort | filter : { product_name : textname} as results">
<ul>
<li><b>Product:</b><span> {{dat.product_name}}</span></li>
<li><b>Product Manager:</b><span> {{dat.first_name}} {{dat.last_name}}</span></li>
<li><b>Status:</b><span> {{dat.status}}</span></li>
<li><b>Description:</b><span> {{dat.description}}</span></li>
</ul>
<!--Comment Button -->
<button style="background-color:#4C97C8;color:white;height:30px" class="btn" ng-click="comment=true;$parent.showcomments(dat.id)"><span class="glyphicon glyphicon-comment"></span><strong> Comment</strong></button>
<!--Comment Box -->
<div ng-show="comment">
<div class="detailBox col-lg-12">
<div class="titleBox">
<label>Comment Box</label>
<button type="button" class="close" aria-hidden="true" ng-click="comment=false">×</button>
</div>
<div class="actionBox">
<ul class="commentList">
<li ng-repeat="sh in showallcomments">
<div class="commenterImage">
<img src="" />
</div>
<div class="commentText">
<p class="">{{sh.comment}}</p> <span class="date sub-text">{{sh.date_created}}</span>
</div>
</li>
</ul>
<div class="input-group ">
<input type="text" id="commentarea" name="commentarea" class="form-control" placeholder="Your Comments" aria-describedby="basic-addon2" ng-model="takecomment">
<span class="input-group-addon" id="basic-addon2" ng-click="takecomment=mycomment(dat.id,takecomment)"><span class="glyphicon glyphicon-send"></span></span>
</div>
</div>
</div>
</div>
</div>
Can you try:
<button style="background-color:#4C97C8;color:white;height:30px" class="btn" ng-click="$parent.commentId=dat.id;$parent.showcomments(dat.id)"><span class="glyphicon glyphicon-comment"></span><strong> Comment</strong></button>
and
<div ng-show="dat.id===$parent.commentId">
I think you are showing the content through modal "showallcomments". which is over-writing every time when you click on comment button.
I mean to say you are binding same variable in all comment boxes.
<div class="col-lg-12" ng-repeat="dat in details | orderBy : sortColumn : reverseSort | filter : { product_name : textname} as results">
<ul>
<li><b>Product:</b><span> {{dat.product_name}}</span></li>
<li><b>Product Manager:</b><span> {{dat.first_name}} {{dat.last_name}}</span></li>
<li><b>Status:</b><span> {{dat.status}}</span></li>
<li><b>Description:</b><span> {{dat.description}}</span></li>
</ul>
<!--Comment Button -->
<button style="background-color:#4C97C8;color:white;height:30px" class="btn" ng-click="showCommentBox($index);$parent.showcomments(dat.id)">
<span class="glyphicon glyphicon-comment"></span><strong> Comment</strong></button>
<!--Comment Box -->
<div ng-show="dat.showComment">
<div class="detailBox col-lg-12">
<div class="titleBox">
<label>Comment Box</label>
<button type="button" class="close" aria-hidden="true" ng-click="comment=false">×</button>
</div>
<div class="actionBox">
<ul class="commentList">
<li ng-repeat="sh in showallcomments">
<div class="commenterImage">
<img src="" />
</div>
<div class="commentText">
<p class="">{{sh.comment}}</p> <span class="date sub-text">{{sh.date_created}}</span>
</div>
</li>
</ul>
<div class="input-group ">
<input type="text" id="commentarea" name="commentarea" class="form-control" placeholder="Your Comments" aria-describedby="basic-addon2" ng-model="takecomment">
<span class="input-group-addon" id="basic-addon2" ng-click="takecomment=mycomment(dat.id,takecomment)"><span class="glyphicon glyphicon-send"></span></span>
</div>
</div>
</div>
</div>
</div>
showCommentBox = function(index){
angular.forEach('details', function(value, key){
if(key == index){
value.showComment = true;
}else{
value.showComment = false;
}
})
}

How to use ng-show and ng-hide in ng-repeat loop

Here i have the code:
<ul dnd-list="list" ng-controller="Modalcontrol">
<li ng-repeat="item in list" ng-click="showAdvanced($event)">
{{item.card_name}}
</li>
</ul>
<span ng-click="$parent.selectedIndex=$index">Add </span>
<md-card class="card" ng-show="$parent.selectedIndex == $index" >
<form name="colorForm" class="addcontdrag" >
<md-input-container>
<label>Add text</label>
</md-input-container>
<span>
<md-button class="md-raised md-primary">Save</md-button>
<i class="material-icons" ng-click="$parent.selectedIndex=$index">clear</i>
</span>
</form>
</md-card>
In this code i want to hide the md-card when i click the close button. Show the md-card by using $parent.selectedIndex=$index. But i dont know how to hide the md-card using this one.
If anyone know please help me.
Thanks Advanced...
You will have to place your md-card inside li tag to get the $index.
<ul dnd-list="list" ng-controller="Modalcontrol">
<li ng-repeat="item in list" ng-click="showAdvanced($event)">
{{item.card_name}}
<span ng-click="$parent.selectedIndex=$index">Add </span>
<md-card class="card" ng-show="$parent.selectedIndex == $index" >
<form name="colorForm" class="addcontdrag" >
<md-input-container>
<label>Add text</label>
</md-input-container>
<span>
<md-button class="md-raised md-primary">Save</md-button>
<i class="material-icons" ng-click="$parent.selectedIndex=$index">clear</i>
</span>
</form>
</md-card>
</li>
</ul>

Angular ui timepicker pop up not showing up

The following code not showing up pop up timepicker. Any idea how to fix?
Code:
<ul class="dropdown-menu custom-scroll dropDownLabel custom-width" role="menu" aria-labelledby="btn-append-to-body"
ng-show="!sr.timedisplay"
>
<li role="menuitem">
<a href="" ng-click="$event.stopPropagation()">Start Time
<p class="input-group">
<input type="text" class="form-control" timepicker-popup ng-model="sr.startTime" is-open="opened" timepicker-options="timeOptions" ng-required="true"/>
<span class="input-group-btn">
<button class="btn btn-default" ng-click="sr.getTime('startTime')"><i class="glyphicon glyphicon-time"></i></button>
</span>
</p>
</a>
</li></ul>
There is no such thing as a timepicker-popup, at least not in the official documentation - the question is tagged as angular-ui-bootstrap?
But you can create one by yourself using the timepicker and a dropdown :
<span uib-dropdown auto-close="outsideClick">
<a href uib-dropdown-toggle>
{{ displayTime }}
</a>
<ul class="uib-dropdown-menu">
<li>
<uib-timepicker ng-model="mytime" hour-step="hstep" minute-step="mstep" show-meridian="ismeridian"></uib-timepicker>
</li>
</ul>
</span>
the script is basically the same as from the timepicker docs, besides a displayTime used for the dropdown :
$scope.$watch('mytime', function(newValue, oldValue) {
var hour = $scope.mytime.getHours()-($scope.mytime.getHours() >= 12 ? 12 : 0),
hour = hour<10 ? '0'+hour : hour,
minutes = ($scope.mytime.getMinutes()<10 ? '0' :'') + $scope.mytime.getMinutes(),
period = $scope.mytime.getHours() >= 12 ? 'PM' : 'AM';
$scope.displayTime = hour+':'+minutes+' '+period
})
plnkr -> http://plnkr.co/edit/J4alKogyKuevSGdTkLFQ?p=preview
NB: The plnkr is in 0.14.3. If you are using Angular UI Bootstrap prior to 0.14.0 then of course skip the uib- prefixes and it will work.
button style with glyph :
<span class="btn btn-default" uib-dropdown auto-close="outsideClick" >
<a href uib-dropdown-toggle>
{{ displayTime }} <i class="glyphicon glyphicon-time"></i>
</a>
<ul class="uib-dropdown-menu">
<li>
<uib-timepicker ng-model="mytime" hour-step="hstep" minute-step="mstep" show-meridian="ismeridian"></uib-timepicker>
</li>
</ul>
</span>
http://plnkr.co/edit/fyC6TfDsrJqsuGCqm11t?p=preview
This used to work:
<uib-timepicker></uib-timepicker>
Now you need to do this:
<div uib-timepicker></div>
based David's sample/input, here is a sample with input component in html, but no controller. And I tested it against Firefox and Chrome, it works well. BTW, I am using bootstrap v3.3.6 and Angular UI bootstrap v1.3.2.
<div class="row">
<div class="col-md-2" style="text-align: right">
<label>Time Picker Popup</label>
</div>
<div class="col-md-2">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-btn" uib-dropdown auto-close="outsideClick">
<button type="button" class="btn btn-default dropdown-toggle" uib-dropdown-toggle><i class="glyphicon glyphicon-time"></i></button>
<ul class="dropdown-menu dropdown-menu-right" uib-dropdown-menu>
<li><uib-timepicker ng-model="mytime" hour-step="1" minute-step="15" show-meridian="false"></uib-timepicker>
</ul>
</div>
</div>
</div>
</div>

How to check whether the value of my scope data is changed or not in angularjs?

I have created a html for customized dropdown.path of below html is "partials/institutions/coordinatorDropdown.html"
<div class="dropdown" ng-click="toggleDropDown">
<button class="form-control overflow" type="button" id="dropdownMenu-list" data-toggle="dropdown" name="datatype" id="datatype" ng-required="true" ng-class="{ 'selected-class-name': $index == selectedIndex }" ng-model="coordinator.role" ng-bind="coordinator.role" required>
</button>
<ul class="dropdown-menu dropdown-menu-list" role="menu" aria-labelledby="dropdownMenu-list" ng-init="toggleDropDown = true" ng-show="toggleDropDown" >
<li role="presentation" ng-repeat="item in role" value="{{ item.roleid }}" ng-click="changeCoordinatorType(item.value, $index)">
<span ng-class="{ 'dropdown-selected-item': $index == selectedIndex }">{{ item.coordinator_type }}</span>
</li>
</ul>
</div>
In my original html i am using this like below:
<div class="col-md-6">
<div class="error-message">
<span ng-show="addCoordinatorForm.coordinatorType.$error.required && !addCoordinatorForm.coordinatorType.$pristine"
class="errormessage" ng-bind="'Please select a coordinator type.'"></span>
</div>
<div name="coordinatorType" ng-include="'partials/institutions/coordinatorDropdown.html'"></div>
</div>
Now in my controller,
I need to check whether the $scope.coordinator.role value is changed or not.
In my controller when i give
if ($scope.addCoordinatorForm.$dirty){
}
It is checking the other controls but not the dropdown value changed or not.
Can anyone suggest a solution for me please?.

Resources