Can't get partial to refresh when model changes - javascript

I have a drop down that is populated witht eh following code:
<span class="bluedept">Department:</span>
<select class="selectpicker deptpicker" selectpicker ng-model="department" ng-controller="CaseListCtrl" ng-change="getCalendar();">
<option ng-repeat="department in departments track by $index">{{department.CourtRoom}}</option>
</select>
I then have this in my controller:
JBenchApp.controller('CaseListCtrl', ['$scope', '$http',
function ($scope, $http) {
// Case list stuff here
$scope.getCalendar = function () {
var e = document.getElementById("deptSelect");
var department = e.options[e.selectedIndex].text;
console.log(department);
$http.get('http://10.34.34.46/BenchViewServices/api/Calendar/LA/' + department + '/08-27-2015').success(function (response) {
$scope.cases = response;
});
}
$http.get('http://10.34.34.46/BenchViewServices/api/CourtDept/LA').success(function (response) {
$scope.departments = response;
});
}]);
The $scope.cases updates with new data, but the partial doesn't change to match that. What can I do to make the partial view refresh?
EDIT TO ADD PARTIAL VIEW CODE:
<div class="row" ng-show="$parent.loggedin">
<div class="col-sm-12 calselectrow">
<div class="inner-addon left-addon">
<span class="glyphicon glyphicon-calendar calicon"></span>
<input type="text" id="calpick" ng-model="date" jdatepicker />
<i class="glyphicon glyphicon-calendar calclick"></i>
>>
<span class="bluedept">Department:</span>
<select class="selectpicker deptpicker" id="deptSelect" selectpicker ng-model="department" ng-controller="CaseListCtrl" ng-change="getCalendar();">
<option ng-repeat="department in departments track by $index">{{department.CourtRoom}}</option>
</select>
</div>
</div>
</div>
<div class="row" ng-show="$parent.loggedin">
<div ng-controller="CaseListCtrl">
<div class="col-sm-8 col-sm-offset-2 caselist" ng-repeat-start="case in cases track by $index">
<div class="sequence">
<input type=text class="seq-box" size="1" value="{{case.sequence}}" />
</div>
<div class="casetitle">
<span class="caselink">{{case.Case_Number}}</span>
<a href="calendar" data-toggle="tooltip" data-placement="top" title="Calendar" class="btn btn-xs btn-danger calicon-view" tooltip>
<span class="glyphicon glyphicon-calendar"></span>
</a>
<a href="documents/{{case.Case_Number}}" data-toggle="tooltip" data-placement="top" title="Documents" class="btn btn-xs btn-danger calicon-view" tooltip>
<span class="glyphicon glyphicon-file"></span>
</a>
<a href="parties/{{case.Case_Number}}" data-toggle="tooltip" data-placement="top" title="Parties" class="btn btn-xs btn-danger calicon-view" tooltip>
<span class="glyphicon glyphicon-user"></span>
</a>
{{case.Case_Title}}
</div>
</div>
<div class="col-sm-8 col-sm-offset-2 caselist-bottom">
<div class="col-sm-9 col-sm-offset-1">
<div class="hearing-time">{{case.Sched_Time}} {{case.AmPm}}</div>
<div class="hearing-title">{{case.Event}}</div>
</div>
</div>
<div ng-repeat-end></div>
</div>
</div>

Try tracking the cases by their id or remove track by from the ng-repeat.
ng-repeat not update model with track by
UPDATE:
I think the issue is that your are using ng-controller twice within your html causing a second scope to be created. Wrap your html in a container div and apply the ng-controller attribute to that only.

Related

Add class to parent div if it has a span as child

I have number of filters to show products in my shop. I'm using bootstrap-select to style the filter (dropdowns).
When I change a filter value, the other filters automatically hide options if there are no results available for that combination.
The problem is, that there a re now Filters that show that don't have any available options to choose from. In this case I want to hide the Filter completely.
If there are options available the code looks like this:
<div class="form-group ">
<label>Serie</label>
<div class="btn-group bootstrap-select show-tick js-wpv-filter-trigger form-control open"><button type="button" class="btn dropdown-toggle bs-placeholder btn-dropdown btn-default" data-toggle="dropdown" role="button" data-id="wpv_control_select_wpcf-serie" title="Bitte wählen..." aria-expanded="true">
<span class="filter-option pull-left">Bitte wählen...</span>
<span class="bs-caret">
<span class="caret"></span>
</span>
</button>
<div class="dropdown-menu open" role="combobox">
<ul class="dropdown-menu inner" role="listbox" aria-expanded="true">
<li data-original-index="0"><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="false"><span class="text">D-9</span><span class="fontawesome fa fa-check check-mark"></span></a></li>
</ul>
</div>
<label class="custom-select">
<select id="wpv_control_select_wpcf-serie" name="wpv-wpcf-serie[]" class="selectpicker js-wpv-filter-trigger form-control" multiple="multiple" tabindex="-98">
<option value="D-9">D-9</option>
</select>
<span></span>
</label>
</div>
</div>
If there is no option available, the code looks like this:
<div class="form-group">
<label>Passend für Helm</label>
<div class="btn-group bootstrap-select show-tick js-wpv-filter-trigger form-control open">
<button type="button" class="btn dropdown-toggle bs-placeholder btn-dropdown btn-default" data-toggle="dropdown" role="button" data-id="wpv_control_select_wpcf-kompatibilitat-extern-mechanisch" title="Bitte wählen..." aria-expanded="true">
<span class="filter-option pull-left">Bitte wählen...</span>
<span class="bs-caret">
<span class="caret"></span>
</span>
</button>
<div class="dropdown-menu open" role="combobox">
<ul class="dropdown-menu inner" role="listbox" aria-expanded="true"></ul>
</div>
<label class="custom-select">
<select id="wpv_control_select_wpcf-kompatibilitat-extern-mechanisch" name="wpv-wpcf-kompatibilitat-extern-mechanisch[]" class="selectpicker js-wpv-filter-trigger form-control" multiple="multiple" tabindex="-98">
</select>
<span></span>
</label>
</div>
</div>
My goal is to add a class .hide-filter to .form-group if the child .dropdown-menu has no li
try below code where you can iterate each form-group and find if it contains dropdown with no li.
$(function(){
$('.form-group').each(function(){
var $dropdown = $(this).find('.dropdown-menu');
if($dropdown.find('li').length==0) {
$(this).addClass('hide-filter');
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="form-group">
<label>Passend für Helm</label>
<div class="btn-group bootstrap-select show-tick js-wpv-filter-trigger form-control open"><button type="button" class="btn dropdown-toggle bs-placeholder btn-dropdown btn-default" data-toggle="dropdown" role="button" data-id="wpv_control_select_wpcf-kompatibilitat-extern-mechanisch" title="Bitte wählen..." aria-expanded="true"><span class="filter-option pull-left">Bitte wählen...</span> <span class="bs-caret"><span class="caret"></span></span></button>
<div
class="dropdown-menu open" role="combobox">
<ul class="dropdown-menu inner" role="listbox" aria-expanded="true"></ul>
</div><label class="custom-select"><select id="wpv_control_select_wpcf-kompatibilitat-extern-mechanisch" name="wpv-wpcf-kompatibilitat-extern-mechanisch[]" class="selectpicker js-wpv-filter-trigger form-control" multiple="multiple" tabindex="-98"></select><span></span></label></div>
</div>
This is another approach:
$( document ).ready(function() {
if($( ".dropdown-menu.inner:has(li)" ).length == 0){
$( ".form-group" ).addClass( "hide-filter" );
}
});

How to get all the input elements data of a current div?

This is my HTML code:
<div data-repeater-item class="mt-repeater-item prescribeData">
<div class="mt-repeater-cell">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon input-circle-left capsule-lightblue">
<i class="fa fa-stethoscope blue-icon-font"></i>
</span>
<input type="text" id="prescribe_test" class="form-control typeahead-prescribetest input-circle-right" placeholder="Prescribe Test">
</div>
<span class="help-block">Name of Investigation</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon input-circle-left capsule-lightblue">
<i class="fa fa-stethoscope blue-icon-font"></i>
</span>
<input type="text" id="diagnosis_input" class="form-control typeahead-diagnosis input-circle-right" placeholder="Duration of Investigation (Optional)">
</div>
<span class="help-block">e.g. Once, Weekly, Monthly</span>
</div>
</div>
<div class="col-md-1 pull-right col-sm-6 col-xs-6">
<a href="javascript:;" style="margin-right:20px;" class="btn-circle prescribeAddData btn green-meadow mt-repeater-btn-inline"> <i class="fa fa-plus"></i>
</a>
</div>
</div>
</div>
</div>
I want to get all the input elements data in a variable using a JQuery code:
I am currently using this code:
$(document.body).on('click', 'a.prescribeAddData', function ()
{
console.log($(this).closest($(".prescribeData :input")));
});
But this code doesn't display the data that the elements are holding after inputting in it.
How can I fix this logic?
You can use the find method to find all elements that are children of a specific element then iterate over them, and store the values in an array for example.
var inputFields = $('.prescribeData').find('input');
var values = [];
inputFields.each(function(){
values.push($(this).val())
})
console.log(values)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div data-repeater-item class="mt-repeater-item prescribeData">
<div class="mt-repeater-cell">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon input-circle-left capsule-lightblue">
<i class="fa fa-stethoscope blue-icon-font"></i>
</span>
<input type="text" id="prescribe_test" class="form-control typeahead-prescribetest input-circle-right" placeholder="Prescribe Test">
</div>
<span class="help-block">Name of Investigation</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon input-circle-left capsule-lightblue">
<i class="fa fa-stethoscope blue-icon-font"></i>
</span>
<input type="text" id="diagnosis_input" class="form-control typeahead-diagnosis input-circle-right" placeholder="Duration of Investigation (Optional)">
</div>
<span class="help-block">e.g. Once, Weekly, Monthly</span>
</div>
</div>
</div>
</div>
</div>

Edit fields in angularjs

Hi I am a beginner in Angularjs and was trying to implement edit of a field and trying to save the data..
The below is the html:-
<div class="row" ng-if="showme=='false'">
<div class="myaddress">
<div class="card-addresses">
<div class="card card-address" ng-repeat="address in addresses" ng-click="selectAddress(address)" ng-class="{active : selectedAddress === address}">
<div class="overlay">
<div class="icon icon-approved"></div>
</div>
<div class="card-header">
<div class="pull-left"><span>{{address.label}}</span></div>
<div class="pull-right"><i class="fa fa-pencil" ng-click="editAddress(address)"></i>
<div class="editpopup editpopup-{{istrue}}">
<p>edit id:
<input type="text" ng-model="address.street"/>
</p>
<p>edit pname:
<input type="text" ng-model="address.station"/>
</p>
<button ng-click="save()">save</button>
<button ng-click="closepopup()">cancel</button>
</div> <i class="fa fa-trash" ng-click="delAddress(address)"></i>
</div>
</div>
<div class="card-block">
<p>{{address.building}}</p>
<p>{{address.street}}</p>
<p>{{address.station}} {{address.city}} - {{address.pincode}}</p>
</div>
<div class="card-footer"><span>Default</span></div>
</div>
</div>
<button class="btn btn-success btn-block" type="button" ng-click="addAddress()">Add New Address</button>
</div>
The below is the js:-
$scope.editrow=function($index){
$scope.istrue=true;
$scope.$index = $index;
angular.copy($scope.address[$index], $scope.address);
}
$scope.closepopup=function(){
$scope.istrue=false;
}
$scope.save = function() {
$scope.istrue=false;
angular.copy($scope.addresses, $scope.addresses[0])
Address.save($scope.addresses)
};
I am trying to fetch and save the data in the service Address which gets getting the value from the database
You need store edit state in each address
So html
<div class="row" ng-if="showme=='false'">
<div class="myaddress">
<div class="card-addresses">
<div class="card card-address" ng-repeat="address in addresses" ng-click="selectAddress(address)" ng-class="{active : selectedAddress === address}">
<div class="overlay">
<div class="icon icon-approved"></div>
</div>
<div class="card-header">
<div class="pull-left"><span>{{address.label}}</span></div>
<div class="pull-right"><i class="fa fa-pencil" ng-click="editAddress(address)"></i>
<div class="editpopup editpopup-{{address.istrue}}">
<p>edit id:
<input type="text" ng-model="address.street"/>
</p>
<p>edit pname:
<input type="text" ng-model="address.station"/>
</p>
<button ng-click="save(address)">save</button>
<button ng-click="closepopup(address)">cancel</button>
</div> <i class="fa fa-trash" ng-click="delAddress(address)"></i>
</div>
</div>
<div class="card-block">
<p>{{address.building}}</p>
<p>{{address.street}}</p>
<p>{{address.station}} {{address.city}} - {{address.pincode}}</p>
</div>
<div class="card-footer"><span>Default</span></div>
</div>
</div>
<button class="btn btn-success btn-block" type="button" ng-click="addAddress()">Add New Address</button>
</div>
And js
$scope.editrow=function($index){
$scope.istrue=true;
$scope.$index = $index;
//angular.copy($scope.address[$index], $scope.address); // why you need this?
}
$scope.closepopup=function(address){
address.istrue=false;
}
$scope.save = function() {
address.istrue=false;
// angular.copy($scope.addresses, $scope.addresses[0])// why you need this?
Address.save($scope.addresses)
};

show div on other page angularjs

I have a div with property information in india, if a user clicks on a button,
the page should be redirect on another page and my whole div should be copy
and open on another page
<div class="box2">
<div style="">
<img src="2.jpg" style="border: 2px solid #EEEEEE; height: 180px;" class="col-lg-6 col-md-6 col-sm-12 col-xs-12" />
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 select">
<div class="borderdiv">
<span ng-repeat="i in data2" style="font-size:16px; font-weight:bold">{{i.A}}</span>
</div>
<div class="borderdiv">
<span ng-repeat="i in data2" style="font-size:12px; font-weight:lighter">Available For <b>{{i.B}}</b> </span>
</div>
<div class="borderdiv">
<span ng-repeat="i in data2" style="font-size:14px; font-weight:normal">Area <b>{{i.C}}</b> Security <b> Rs. {{i.F}}</b></span>
</div>
<div class="borderdiv">
<span ng-repeat="i in data2" style="font-size:14px; font-weight:normal">Rental Unit In<b style="cursor:pointer"> {{i.D}}</b></span>
</div>
<br />
<div class="borderdiv">
<span ng-repeat="i in data" style="font-size:14px; font-weight:normal">
Features
<br />
<span class="glyphicon glyphicon-eject" style="margin-left:20px;"></span>
<span class="glyphicon glyphicon-chevron-left" style="margin-left:20px;"></span>
<span class="glyphicon glyphicon-chevron-right" style="margin-left:20px;"></span>
</span>
</div>
<br />
<div class="borderdiv">
<span ng-repeat="i in data2" style="font-size:14px; font-weight:normal">{{i.E}}</span>
</div>
</div>
</div>
this is my div
<button ng-click="click()">click to view data</button>
this is my button
what i need to do if i want to see the same data on other pages???
You need to create a server-side structural template which will generate the div. Example in PHP
function getViewData() {
?>
<button ng-click="click()">click to view data</button>
>?php
}
And you can add anywhere in your structure if you are using a PHP file like this:
<?php getViewData(); ?>
I will suggest you to go with a angular factory which contains the data that you are looking for and use the html template in the respective page.
Button code remains the same as
<button ng-click="click()">click to view data</button>
Create a new Angular Factory as below
angular.module('myApp').factory('appVariables',function(){
var data2=[];
return{
data2,data2
}
});
Your controller should contain the following click() method
angular.module('myApp').controller('appController',function($scope,appVariables){
$scope.click=function(){
appVariables.data2=$scope.data2;
}
})
Go to the another page inject appVariables as a dependecy to the controller and you can get the same data2 across your app.
This code is genric as the information provided by you is very less.
I have put together a sample for you. I can't create multiple html pages. So you have to put them in different files.
var app = angular.module('sample', []);]
//JS1
app.controller('page1Controller', ['$scope','$http','$rootScope', function($scope, $http){
$scope.page1 = {};
$scope.page1.title = "Page1";
$scope.click = function(page){
$rootScope.page = page;
}
}]);
//JS2
app.controller('page2Controller', ['$scope','$http','$rootScope', function($scope, $http){
$scope.init = function(){
alert("alrt")
$scope.page2 = $rootScope.page;
}
}]);
<div ng-app="sample">
<!--Page1-->
<div ng-controller="page1Controller">
<div>{{page1.title}}</div>
<button ng-click="click(page1)">click to view data</button>
</div>
<!--Page2-->
<div ng-app="sample">
<div ng-controller="page2Controller" ng-init="init()">
<div>{{page2.title}}</div>
</div>

Dropdown holding of value in Angular view

I have a unique situation. I have a dropdown called caseStatus (see code below) and it is actually being written out during an ng-repeat, but it is tied to a model that contains the list of Case Statuses. Obviously there are multiple of these dropdowns on the page once it is rendered. All of that works just fine. The issue is that the judge can change the status of the case. I am working on a function that will handle that and I am confident it will work. My question is how to do the following two things (which are perhaps both solved with one method I suspect):
Make sure that each dropdown maintains its last value when a page is refreshed or returned to.
Make sure that it loads to what was last there during the ng-repeat. There is a field in the model that the ng-repeat is using that has the value for the Case Status.
Here is the code. There is a comment that says which dropdown is in question:
<div ng-controller="CaseListCtrl">
<div class="row" ng-show="$parent.loggedin">
<div class="col-sm-12 calselectrow">
<div class="inner-addon left-addon">
<span class="glyphicon glyphicon-calendar calicon"></span>
<input type="text" id="calpick" ng-model="date" jdatepicker />
<i class="glyphicon glyphicon-calendar calclick"></i>
>>
<span class="bluedept">Department:</span>
<select class="selectpicker deptpicker" id="deptSelect" selectpicker data-ng-model="department" ng-change="getCalendar();">
<option ng-repeat="department in departments">{{department.CourtRoom}}</option>
</select>
</div>
</div>
</div>
<div class="row" ng-show="$parent.loggedin">
<div>
<div class="col-sm-8 col-sm-offset-2 caselist" ng-model="cases" ng-repeat-start="case in cases | orderBy: ['sequence', 'AmPm', 'Sched_Time', 'Case_Number']">
<div class="sequence">
<input type=text class="seq-box" size="1" value="{{case.sequence}}" />
<!-- Add hidden field to hold the CalendarID value for updating the sequence later-->
<input type="hidden" name="CalendarID_{{case.Case_Number}}" value="{{case.CalendarID}}" />
</div>
<div class="casetitle">
<span class="caselink">{{case.Case_Number}}</span>
<a href="calendar" data-toggle="tooltip" data-placement="top" title="Calendar" class="btn btn-xs btn-danger calicon-view" tooltip>
<span class="glyphicon glyphicon-calendar"></span>
</a>
<a href="documents/{{case.Case_Number}}" data-toggle="tooltip" data-placement="top" title="Documents" class="btn btn-xs btn-danger calicon-view" tooltip>
<span class="glyphicon glyphicon-file"></span>
</a>
<a href="parties/{{case.Case_Number}}" data-toggle="tooltip" data-placement="top" title="Parties" class="btn btn-xs btn-danger calicon-view" tooltip>
<span class="glyphicon glyphicon-user"></span>
</a>
<select class="form-control" id="caseStatus" name="caseStatus" ng-model="caseStatus.statusID" ng-change="setStatus();" ng-options="castStatus.statusName for caseStatus in castStatus track by caseStatus.statusName" required></select><!-- This is the dropdown in question-->
{{case.Case_Title}}
</div>
</div>
<div class="col-sm-8 col-sm-offset-2 caselist-bottom">
<div class="col-sm-9 col-sm-offset-1">
<div class="hearing-time">{{case.Sched_Time}} {{case.AmPm}}</div>
<div class="hearing-title">{{case.Event}}</div>
</div>
</div>
<div ng-repeat-end></div>
</div>
</div>
</div>
How do I accomplish this?
Are you developing a SPA (single page application)? What do you mean by "page is refreshed or returned to"? If you are reloading the whole page, then there is no way to retrieve the last values, as the controllers will reinitialize. You'll have to save the values somewhere, e.g. database or cookie, and retrieve them from a service that is injected into your controller...

Categories

Resources