Hi I don't know if I'm making this correct. What I'm doing is I'm getting the value of mode of payment and passing it to #editregistrationmodeofpayment.
The code looks like this.
$("#editregistrationmodeofpayment").val(response.registration_mode_of_payment);
What I want to do, and I'm having a problem in this is if the value of response.registration_mode_of_payment is = 'Monthly' it will load a controller of mine.
What I've done already looks like this.
$("#editregistrationmodeofpayment").val(response.registration_mode_of_payment, function(){
if($(this).val() == 'Monthly') {
// Loads the controller
$("#editmodeofpayment").load('registration/assessModeofPayment/'+schoolyearId+'/'+response.gradelevel_id);
}
else { document.getElementById("editmodeofpayment").innerHTML = ""; }
});
Is it possible to do this?
It seems to me that response.registration_mode_of_payment is holding the value that you want to do an if statement on. So this should do it:
if (response.registration_mode_of_payment === 'monthly') {
// Loads the controller
$("#editmodeofpayment").load('registration/assessModeofPayment/'+schoolyearId+'/'+response.gradelevel_id);
}
else { document.getElementById("editmodeofpayment").innerHTML = ""; }
Related
I have the following code. There is a button in the UI that when clicked executes the if statement. I pass in a URL from a database and compare it to the current URL the user is on. If they match I want to run the code below, else I want to open the correct tab then run the code below.
With this code below I mean everything below starting from $('#sceanrioDropdownList').change(function () {...}. The code then checks a drop down and gets the selected Id from which an AJAX call is made to my web API that uses that Id in a stored procedure to return the results. The returned data is then iterated over and stored in variables which I am using to append to specific inputs, buttons and drop downs.
This is what I have so far and I think I have developed this correctly. The issue that I am currently having is that the UI wants everything from ... to be run if the if statement is true. I have tried CTRL+C and CTRL+V to copy the code into the if statement. I have also tried putting it in a new function and referencing that function n the if statement. Both do not work and I was using console.log to inspect the returned data.
It does however when I attempt to call it from inside i statement it doesn't return any data or error. It just doesn't seem to fire.
Is there a way in which I can achieve the functionality I desire? Do you have any suggestions as to if I have done something wrong. Thanks in advance.
$('#automate').click(automateButton);
function automateButton() {
if (webpageUrl == activeTabUrl) {
// do nothing
} else {
// Window opens
window.open(webpageUrl);
}
}
$('#scenarioDropdownList').change(function() {
var scenarioId = $('#scenarioDropdownList option:selected').prop('id');
getData(scenarioId);
});
function getData(scenarioId) {
$.ajax({
type: "GET",
url: 'http://localhost:54442/api/scenariodatas/GetScenarioData',
data: {
scenarioId: scenarioId
},
dataType: 'JSON',
success: scenarioData,
error: function() {
console.log("There has been an error retrieving the data");
}
});
}
function scenarioData(response) {
$.each(response, function(key, val) {
var fieldType = val.fieldType;
var fieldName = val.fieldName;
var fieldValue = val.fieldValue;
var field = $(fieldName);
if (field != undefined) {
switch (fieldType) {
case "Input":
$(field).val(fieldValue);
break;
case "Button":
$(field).click();
break;
case "Select":
$(field).val(fieldValue);
break;
}
}
})
}
onChange don´t work well with buttons because onChange detect a change in the value of your component, because of this, it´s highly recommended to use onClick when you use a button.
$('#scenarioDropdownList').click(function() {
var scenarioId = $('#scenarioDropdownList option:selected').prop('id');
getData(scenarioId);
});
I recommend you to put alerts when you are trying to test this sort of JS
EJM:
$('#scenarioDropdownList').change(function() {
alert('button active');
var scenarioId = $('#scenarioDropdownList option:selected').prop('id');
getData(scenarioId);
});
this alert allow you to know if the code is firing or not
Here's the problem. I'm making a callback to the server that receives an MVC partial page. It's been working great, it calls the success function and all that. However, I'm calling a function after which iterates through specific elements:
$(".tool-fields.in div.collapse, .common-fields div.collapse").each(...)
Inside this, I'm checking for a specific attribute (custom one using data-) which is also working great; however; the iterator never finishes. No error messages are given, the program doesn't hold up. It just quits.
Here's the function with the iterator
function HideShow() {
$(".tool-fields.in div.collapse, .common-fields div.collapse").each(function () {
if (IsDataYesNoHide(this)) {
$(this).collapse("show");
}
else
$(this).collapse("hide");
});
alert("test");
}
Here's the function called in that, "IsDataYesNoHide":
function IsDataYesNoHide(element) {
var $element = $(element);
var datayesnohide = $element.attr("data-yes-no-hide");
if (datayesnohide !== undefined) {
var array = datayesnohide.split(";");
var returnAnswer = true;
for (var i in array) {
var answer = array[i].split("=")[1];
returnAnswer = returnAnswer && (answer.toLowerCase() === "true");
}
return returnAnswer;
}
else {
return false;
}
}
This is the way the attribute appears
data-yes-no-hide="pKanban_Val=true;pTwoBoxSystem_Val=true;"
EDIT: Per request, here is the jquery $.post
$.post(path + conPath + '/GrabDetails', $.param({ data: dataArr }, true), function (data) {
ToggleLoader(false); //Page load finished so the spinner should stop
if (data !== "") { //if we got anything back of if there wasn't a ghost record
$container.find(".container").first().append(data); //add the content
var $changes = $("#Changes"); //grab the changes
var $details = $("#details"); //grab the current
SplitPage($container, $details, $changes); //Just CSS changes
MoveApproveReject($changes); //Moves buttons to the left of the screen
MarkAsDifferent($changes, $details) //Adds the data- attribute and colors differences
}
else {
$(".Details .modal-content").removeClass("extra-wide"); //Normal page
$(".Details input[type=radio]").each(function () {
CheckOptionalFields(this);
});
}
HideShow(); //Hide or show fields by business logic
});
For a while, I thought the jquery collapse was breaking, but putting the simple alert('test') showed me what was happening. It just was never finishing.
Are there specific lengths of time a callback function can be called from a jquery postback? I'm loading everything in modal views which would indicate "oh maybe jquery is included twice", but I've already had that problem for other things and have made sure that it only ever includes once. As in the include is only once in the entire app and the layout is only applied to the main page.
I'm open to any possibilities.
Thanks!
~Brandon
Found the problem. I had a variable that was sometimes being set as undefined cause it to silently crash. I have no idea why there was no error message.
Hi I am developing web application in angularjs. I have implemented print functionality. I am binding values to view using scope variables. When i click first time on print my values are not binding. When i click second time all my values will bind. Below is the print functionality.
$scope.Print = function () {
if ($scope.period == null) {
toastr.error($filter('translate')('Please select Year.'));
}
else {
$scope.vehiclepriceprint = $cookieStore.get("carpriceprint");
$scope.downpaymentprint = $cookieStore.get("downpayment");
}
First time also i will be having values in cookie but not binding to view. Whenever i click second time on print button everything will be working
Below is the print button.
<input type="button" value="{{'Print' | translate}}" class="blue-button" ng-click="Print()" id="btnPrint">
Below is the html code of print.
<span id="lblDownPayment">{{downpaymentprint}}</span>
<span id="lblFinancialAmount">{{vehiclepriceprint}}</span>
May i know what is the issue i am facing here? Any help would be appreciated. Thank you.
Try using $scope.$apply(); after updating the model values inside the controller. Now the view will get updated after that. This is a sample.
$scope.Print = function () {
if ($scope.period == null) {
toastr.error($filter('translate')('Please select Year.'));
}
else {
$scope.vehiclepriceprint = $cookieStore.get("carpriceprint");
$scope.downpaymentprint = $cookieStore.get("downpayment");
$scope.$apply(); // To update view
}
}
Try using $apply. Although this is not a good approach.
$scope.Print = function () {
if ($scope.period == null) {
toastr.error($filter('translate')('Please select Year.'));
}
else {
$scope.vehiclepriceprint = $cookieStore.get("carpriceprint");
$scope.downpaymentprint = $cookieStore.get("downpayment");
$timeout(function(){//inject $timeout as dependency
$scope.$apply();
})
}
Edit 1: Try this approach. here I have used Object (key:value) ways to update the print data.
$scope.printData = {};
$scope.Print = function () {
if ($scope.period == null) {
toastr.error($filter('translate')('Please select Year.'));
}
else {
$scope.printData.vehiclepriceprint = $cookieStore.get("carpriceprint");
$scope.printData.downpaymentprint = $cookieStore.get("downpayment");
}
HTML:
<span id="lblDownPayment">{{printData.downpaymentprint}}</span>
<span id="lblFinancialAmount">{{printData.vehiclepriceprint}}</span>
Analysis
Actually, ngClick calls $scope.$apply() under-the-hood (in the safest way possible). So you should not call it explicitly in your Controller.
Problem is that the variables you are trying to display/update are attached directly to the $scope, and this approach usually causes this issue.
Solution
$scope.vm = {};
$scope.Print = function() {
$scope.vm.vehiclepriceprint = $cookieStore.get("carpriceprint");
};
<span id="lblFinancialAmount">{{ vm.vehiclepriceprint }}</span>
Essentially what I need is to run some JavaScript after a record has been saved. This will pick up a guid from a field which has been populated by a plugin. My code looks like;
Xrm.Page.data.entity.save();
var newguid = Xrm.Page.getAttribute("new_copyguid").getValue();
Xrm.Utility.openEntityForm("new_myentity", newguid);
The problem is the code runs past the call to save() and continues executing before a plugin has populated the "new_copyguid" field. Is there a way to wait for the plugin to complete before continuing with the javascript? I have tried AddOnSave() without success. Any javascript callback seems to execute before the plugin finishes as well. The plugin is set to run synchronously.
I am performing this javascript from a button on the form. The button sets a field value and then saves the record, triggering the plugin. The button is a "Copy Entity" button which creates a clone. I need to open this new record in the browser.
I have read that this does not work either, as it happens before the save;
Xrm.Page.data.refresh(save).then(successCallback, errorCallback);
Any pointers would be great!
I think you'll have to run your logic in the OnLoad section. The save should force a refresh and your onload logic will run again. You'll need to do some check to see if the modified on date is within a certain time frame.
Other option is you perform the update manually through a rest call or Soap call, then you can read the value from the plugin in another call.
You can just wait for some seconds by putting this code.
function YourFunction()
{
Xrm.Page.data.entity.save();
OpenForm();
}
Its a new function.
function OpenForm()
{
setTimeout(function () {
var newguid = Xrm.Page.getAttribute("new_copyguid").getValue();
Xrm.Utility.openEntityForm("new_myentity", newguid);
}, 3000);
}
Try this:
function onPageLoad() {
var formType = Xrm.Page.ui.getFormType();
if (formType == 0 || formType == 1) { // 0 = Undefined, 1 = Create
// If form is in Create Mode then
if (Xrm.Page.data != null && Xrm.Page.data.entity != null) {
Xrm.Page.data.entity.addOnSave(onSaveDoThis);
}
}
}
function onSaveDoThis() {
setTimeout(onFormSaveSuccess, 300);
}
function onFormSaveSuccess() {
var newguid = Xrm.Page.getAttribute("new_copyguid").getValue();
if (newguid == "") {
onSaveDoThis();
} else {
// Don't need to trigger the function onSaveDoThis anymore
Xrm.Page.data.entity.removeOnSave(onSaveDoThis);
Xrm.Utility.openEntityForm("new_myentity", newguid);
}
}
Try this:
function OpenForm()
{
setTimeout(function () {
var newguid = Xrm.Page.getAttribute("new_copyguid").getValue();
Xrm.Utility.openEntityForm("new_myentity", newguid);
}, 3000);
}
I have this main page that loads another php file on onchange event of the dropdown. I use this to load the page:
function get_value(){
if($("#dropdwn").val()=="0"){
//load nothing
}else{
$('#txtval').val($("#dropdown").val());
$('#load_page').html('<p align="center"><br/><img src="images/popuploader.gif" /><br/><br/></p>');
$('#load_page').load('load_xml.php');
}
}
For now I put the value of dropdown on the textbox but will also try to get the value of dropdown.
The problem is on the second php file that loads on the main page. I can't get the value of $txtval=$_POST['txtval'] when I use this. I will need the value for if else condition.
First you need to sent the parameter to the resource load_xml.php.
function get_value() {
if ($("#dropdwn").val() == "0") {
//load nothing
} else {
var val = $("#dropdown").val();
$('#txtval').val(val);
$('#load_page').html('<p align="center"><br/><img src="images/popuploader.gif" /><br/><br/></p>');
$('#load_page').load('load_xml.php?txtval=' + val);
}
}
The the load method uses a GET request, not a POST method.
$txtval=$_GET['txtval']
If you want to sent a POST method, then use the syntax
function get_value() {
if ($("#dropdwn").val() == "0") {
//load nothing
} else {
var val = $("#dropdown").val();
$('#txtval').val(val);
$('#load_page').html('<p align="center"><br/><img src="images/popuploader.gif" /><br/><br/></p>');
$('#load_page').load('load_xml.php?', {
txtval: val
});
}
}
then
$txtval=$_POST['txtval']