dynamics crm 365 online quickform not rendering - dynamics-crm

I have a form which has a tab and in this tab is a quickview form. On the quickview form, I have a subgrid and a text field.
The tab has a default state of 'collapsed'. When I open the form, only the text field is displayed. It seems as if the subgrid in no rendering at all.
If I change the tab default state to 'expanded', then when I open the form, the
subgrid is rendering correctly.
I have tried to refresh the quickform view outlined here
https://msdn.microsoft.com/en-us/library/mt736908.aspx
But it does not seem to work.
UPDATE:
I have tried the following, but still no success.
FIRST VERSION
// Triggering when the tab is expanded
function onChange(){
console.log('on change');
// get quick view form
var qv = Xrm.Page.ui.quickForms.get("myquickformview");
qv.refresh();
// get subgrid
try {
qv.getControl(0).refresh();
}
catch (e)
{
console.log(e);
}
}
SECOND VERSION
function onLoad(){
console.log('onload');
Xrm.Page.getAttribute('new_person').addOnChange(refresh);
}
function onChange(){
Xrm.Page.getAttribute('new_person').fireOnChange();
}
function refresh(){
console.log('on change');
// get quick view form
var qv = Xrm.Page.ui.quickForms.get("myquickformview");
// get subgrid
try {
qv.getControl(0).setVisible(false);
qv.getControl(0).setVisible(true);
qv.getControl(0).refresh();
}
catch (e)
{
console.log(e);
}
qv.refresh();
}
Any advice appreciated. Thanks in advance.

1.Add onchange event handler for the lookup (on which Quick view form is rendered) to have the code to refresh the quick view control.
Xrm.Page.getAttribute("lookup_fieldname").addOnChange(function);
Keep the below code in function.
var quickViewControl = Xrm.Page.ui.quickForms.get(“your quick view form name”);
if (quickViewControl != undefined) {
if (quickViewControl.isLoaded()) {
quickViewControl.refresh();
}
}
2.Trigger fireOnChange() of lookup on tab expanded handler, so that onchange will refresh QVform totally.
Xrm.Page.getAttribute("lookup_fieldname").fireOnChange();
Got a hint from this. I just answered here (in mobile without testing) to unblock you.

Related

Refresh Parent Form after Quick Create in Dynamics CRM 2016

In Dynamics CRM 2016 we have a Quick Create Form which works well. But once the Quick Create is done, and the record is saved (and the new record appears in the sub-grid in the parent form), the roll-up field under the sub-grid doesn't get re-refreshed on the screen until the user presses F5.
(we have some C# code to update the roll-up).
Does anyone know how to force the refresh of the main form after the Quick Create has successfully run?
You may add timeout on refresh event, and after 1-2 sec refresh once more.
function OnFormLoad() //add this function onload form
{
var subGrid = window.parent.document.getElementById("id of your subgrid")
if (subGrid !== null) {
if (subGrid.control)
subGrid.control.add_onRefresh(fnOnRefresh)
else
setTimeout(OnFormLoad, 500);
} else {
setTimeout(OnFormLoad, 500);
}
}
function fnOnRefresh() {
setTimeout(function() {
Xrm.Page.ui.controls.get("id of your subgrid").refresh();
}, 2000) //after 2 sec refresh subgrid
}
I would try stopping the OOB save event using the below snippet: Read more
function onSave(context) {
var saveEvent = context.getEventArgs();
saveEvent.preventDefault();
//save explicitly here
//reload the window here
}
And then save the entity in code using:
Xrm.Page.data.entity.save();
And then refresh/reload the browser window. I haven’t tried this but very rough theory :)
We got it working ... used what Timur suggested but just changed the last function to:
function fnOnRefresh() {
setTimeout(function() {
window.parent.location.reload(true);
}, 500)
}
Thank you

Kendo UI Gantt - Display a custom modal for task update

I am aware of the following http://docs.telerik.com/kendo-ui/api/javascript/ui/gantt#configuration-editable.template
but it is not what I need.
I need to display a custom modal dialog for task edition that is used in other parts of the app instead of the default kendo dialog.
Here's a possible way:
Implement a handler for the edit event and use e.preventDefault() to cancel kendo's built-in handling. This will prevent their dialog(or the template) from showing.
Now you show your own dialog(however you need to do that) and push in the GanttTask data passed to the edit event.
When your dialog is closed, you push the values of the edited data into the GanttTask...this is important! Since you cancelled the built-in functionality, it is now your responsibility to update the underlying data model.
Example edit handler:
edit: function(e) {
// Cancel the built-in editing functionality
e.preventDefault();
var editResult = showMyDialog(e.task);
if (editResult.ok) {
// User clicked OK instead of Cancel...or whatever mechanism your dialog uses.
e.task.set("title", editResult.data.title);
// other data...
}
}
Example custom dialog:
function showMyDialog(task) {
// Fetch/show your actual window, push in the data from the GanttTask
alert("This is my window: " + task.title);
// Simulate user editing of GanttTask.
var editedTitle = "NeW tAsK!";
// other data...
return {
ok: true, // or false if user clicked cancel.
data: {
title: editedTitle
// other data...
}
};
}
Simple demo: http://dojo.telerik.com/#Stephen/apEYa

jqGrid 'clearToolbar' without grid reload

I need to clear the toolbar without reloading the grid in my jqgrid. It should just reset the toolbar to its default values.
I tried using,
$("#TransactionsGrid")[0].clearToolbar();
My grid datatype:local and i don't use loadonce:true.
This made the toolbar clear and refresh the grid. I dont want that to happen.
Any ideas?
I find the question interesting.
To implement the requirement I suggest to use register jqGridToolbarBeforeClear to execute the handler only once. The handler should 1) unregister itself as the event handler and return "stop" to prevent reloading of the grid:
$grid.jqGrid("filterToolbar", { defaultSearch: "cn" });
$("#clearToolbar").button().click(function () {
var myStopReload = function () {
$grid.unbind("jqGridToolbarBeforeClear", myStopReload);
return "stop"; // stop reload
};
$grid.bind("jqGridToolbarBeforeClear", myStopReload);
if ($grid[0].ftoolbar) {
$grid[0].clearToolbar();
}
});
The corresponding demo shows it live.

JQuery Vector Map: Tooltip remains displayed on the map after click

I am using JQuery VectorMap.
When I click on a country, the tooltip containing the description is shown.
However, when I click on another country, the previously displayed tooltip is not removed from the screen.
I don't understand why the tooltip of the clicked region stays displayed, since the onRegionClick event does not save the state of the tooltip.
Here is the code:
onRegionClick: function(event, code){
if (gdpData[code]) {
$('#currencyHidden').val(wm2idCurrencyMap[code]);
$('#calculatorCurrencyToHidden').val(wm2idCurrencyMap[code]);
$('#calculatorWmCurrencyToHidden').val(wm2idCurrencyMap[code]);
submitCurrenciesFormWithOptions();
}
},
function submitCurrenciesFormWithOptions() {
// sets the form options and submits the form
$('#currenciesForm').ajaxSubmit(currenciesFormOptions);
//submitCalculatorFormWithOptions();
return false;
}
Thank you !
Checked your onLabelShow function.
onLabelShow: function(e, el, code){
el.html(el.html()+' (GDP - '+gdpData[code]+')');
};
jvectormap example site url. http://jvectormap.com/examples/world-gdp/

ASP.NET MVC - How to prevent double click submit with jquery.validate.unobtrusive lib?

I need to avoid the double click submitting behavior. I'm using the client validation with the unobtrusive library. I have the following code for avoiding the double clic:
jQuery.fn.preventDoubleSubmit = function () {
var alreadySubmitted = false;
return jQuery(this).submit(function () {
if (alreadySubmitted)
return false;
else {
alreadySubmitted = true;
}
});
};
jQuery('form').preventDoubleSubmit();
Unfortunately, if my form has some validable fields (for example, a required field), the code above is still being fired, hence, even if I correct any mistakes on the form, I won't be able to submit it again.
How can I fire the double click code after the validation has been succesfully done?
You can also use the JQuery One event.
I have found that I could get past most guards against double-clicks by double-clicking fast. Using the one event is the only true way to make sure the event is only fired once. I don't think this technique will work "out of the box" with an input type=submit tag. Instead, you can simply use an input type=button or JQueryUI's .button().
$("#submitButton").one("click", function(event) {
$('#theForm').submit();
});
If you need to re-wire the event on a validation error (or other circumstance), I recommend that you create a function for the event handler. The function isn't necessary in this example because all the event handler does is submit the form, but in more complicated scenarios you may want to avoid repeating yourself.
function submitClick(event) {
$('#theForm').submit();
}
$("#submitButton").one('click', function(event) {
submitClick(event);
});
// This handler will re-wire the event when the form is invalid.
$('#theForm').submit(function(event) {
if (!$(this).valid()) {
event.preventDefault();
$('#submitButton').one('click', function(event) { submitClick(event); });
}
});
You could obviously add the disabling code here if you wanted to give feedback to the user that the button doesn't work anymore. One great side-effect of using the One event is that you don't actually have to make the button disabled, you can use a style of your own.
function submitClick(event) {
$('#submitButton').addClass('disabledButton');
$('#theForm').submit();
}
$("#submitButton").one('click', function(event) {
submitClick(event);
});
// This handler will re-wire the event when the form is invalid.
$('#theForm').submit(function(event) {
if (!$(this).valid()) {
event.preventDefault();
$('#submitButton').one('click', function(event) { submitClick(event); });
$('#submitButton').removeClass('disabledButton');
}
});
JQuery One Event: http://api.jquery.com/one/
I solved it with the following code:
var tryNumber = 0;
jQuery('input[type=submit]').click(function (event) {
var self = $(this);
if (self.closest('form').valid()) {
if (tryNumber > 0) {
tryNumber++;
alert('Your form has been already submited. wait please');
return false;
}
else {
tryNumber++;
}
};
});
NOTE: You can also replace the:
return false;
line, for:
self.attr('disabled', true);
BUT, if you use the name of your submit buttons on your controller for extra logic, they will be sent as null. (you can use an additional hidden field to charge them before submitting)
that's it, hope it helps
Rodrigo
EDIT: Thanks to these posts:
jquery newbie: combine validate with hidding submit button
Why not just use:
function disableButtons() {
var form = $(this);
var btns = $("input:submit", form);
if (!form.valid()) {
// allow user to correct validation errors and re-submit
btns.removeAttr("disabled");
} else {
btns.attr("disabled", "disabled");
}
}
to disable your buttons and activate it using:
$("form").bind("submit", disableButtons);
Based on Ryan P's popular answer I created the following generic solution that also works with my ajax form.
decorate your custom submit button with the following class:
<button type="button" class="one-click-submit-button">Submit</button>
Add the following to your javascript file:
function OneClickSubmitButton() {
$('.one-click-submit-button').each(function () {
var $theButton = $(this);
var $theForm = $theButton.closest('form');
//hide the button and submit the form
function tieButtonToForm() {
$theButton.one('click', function () {
$theButton.hide();
$theForm.submit();
});
}
tieButtonToForm();
// This handler will re-wire the event when the form is invalid.
$theForm.submit(function (event) {
if (!$(this).valid()) {
$theButton.show();
event.preventDefault();
tieButtonToForm();
}
});
});
}
OneClickSubmitButton();
since this is an ajax form we want to reload the handlers if we fail server validation.
function MyForm_OnSuccess() {
if (true if your form passed validation logic) {
//do something since your form submitted successfully
} else { //validation failed on server
OneClickSubmitButton(); //reinitialize the button logic
}
}
Obviously if you don't have ajax forms you can omit the whole OneClickSubmitButton function business and run $('.one-click-submit-button').each(... directly.
I have a form that uses MVC3 unobtrusive validation, and a viewmodel with a [RemoteAttribute].
It looks to me like the form's submit event only fires after all validation has passed. I'm currently using this, and it seems to work:
<input type="submit" value="Submit the Form"
data-app-disable-on-submit="true" />
$('form').live('submit', function() {
$(this).find('input[type="submit"][data-app-disable-on-submit="true"]')
.attr('disabled', 'disabled');
})
;
I set breakpoints on both the remote attribute validation action method and the HttpPost action method. Clicking the submit button the first time hits the breakpoint on the validation action method. At this point, the button is still enabled. I can click it multiple times, and after resuming the validation method, the HttpPost is hit only once. When the HttpPost is hit, the submit button is disabled.
Update
Right you are Alex. So an updated version of the above would look like this:
$('form').on('submit', function() {
$(this).find('input[type="submit"][data-app-disable-on-submit="true"]')
.attr('disabled', 'disabled');
})
$('form').submit(function () {
$('input[type="submit"]', this).attr('disabled', 'disabled');
});
I use a different approach to this. Not wiring to the click event of the button, but to the submit event of the form. Works like a charm to prevent multiple simultaneous submits of forms.
function initFormsToPreventSimultaneousSubmits(selector) {
if (!selector) {
selector = 'form'; // No selector supplied, apply to all forms on the page
}
// Make sure all forms that conform to selector are marked as not submitting
$(selector).each(function()
{
var $form = $(this);
$form.data('submitting', false);
});
// Attach to submit event of all forms that conform to selector
$(selector).off('submit').on('submit', function (e) {
var $form = $(this);
if (!$form.valid || $form.valid()) { // Make sure to only process when the form is valid or jquery validation is not used
if ($form.data('submitting')) {
// form is already submitting. Classic case of double click on one of the submit buttons of the form. Stop the submit
e.preventDefault();
return false;
} else {
// All ok, mark the form as submitting and let the form perform the submit
$form.data('submitting', true);
return true;
}
}
});
}
On document ready i call initFormsToPreventSimultaneousSubmits() to init all forms on the page.
Only thing to remember is that when u use a ajax form post is to call the initFormsToPreventSimultaneousSubmits('#formId') on the OnComplete event of the AjaxOptions settings. Because otherwise the form will still be marked as submitting when its done. When a 'normal' form post is used this is not an issue.
Extends answers by Alex and Ryan P to accounts for situations where jQuery Validation might be missing and where multiple submit buttons exist in a single form.
oneClickSubmitButton = function () {
$('input[type=submit], button[type=submit], input[type=image]').each(function () {
var $theButton = $(this);
var $theForm = $theButton.closest('form');
//hide the button and submit the form
function tieButtonToForm() {
$theButton.one('click', function () {
$theButton.addClass('ui-state-disabled');
});
}
tieButtonToForm();
$theForm.submit(function (event) {
// Only proceed for the clicked button
if (!$theButton.hasClass("ui-state-disabled"))
return;
// If jQuery Validation is not present or the form is valid, the form is valid
if (!$theForm.valid || $theForm.valid())
return;
// Re-wire the event
$theButton.removeClass('ui-state-disabled');
event.preventDefault();
tieButtonToForm();
});
});
};
I was able to fix a similar issue with a couple of lines of code. I prefer this if you don't want to "alert" to user that they double clicked and just silently ignore the second click.
I just made a global javascript variable that I toggled when my function was executing during a critical section. This kept subsequent function calls from re-executing the same section.
var criticalSection = false;
SomeOnClickEventFired = function () {
if (!criticalSection)
{
criticalSection = true;
//Ajax Time
criticalSection = false;
}
}

Resources