Monday, August 18, 2014

Resizing 2011 entity forms

This is a small issue, and will be a non-issue once everyone move to 2013.
Until then if you need to control the size of your entity forms here is what you would expect to work.

//Resize to screen: 
xrmForm.FitToWindow();

// your SDK resource 
function XrmForm() {
     var xfrm = this;
     
  xfrm.ResizeTo = xfrm.FitToWindow = function () {
        window.resizeTo(arguments[0] || screen.availWidth, 
                        arguments[1] || screen.availHeight);
        return frm;
    }
}

var xrmForm = new XrmForm();


This would work in IE but won’t work in chrome. The reason for this is that chrome has strict rules regarding from where resizeTo works. Since you’re resizing the
window of an IFRAME (edit.aspx – this is where you script runs) and not the main window it won’t resize.
To overcome this obstacle you need to resize the window at the top.

The following will work in all browsers.
//your SDK resource
function XrmForm() {
     var xfrm = this;
    //resize top window
  xfrm.ResizeTo = xfrm.FitToWindow = function () {
        window.top.resizeTo(arguments[0] || screen.availWidth, 
                            arguments[1] || screen.availHeight);
        return frm;
    }
}

var xrmForm = new XrmForm();
Changed window.resizeTo > window.top.resizeTo

Sample Usage
//your entity.js resource

//Resize to screen: 
xrmForm.FitToWindow();
//Resize to give width and height
xrmForm.ResizeTo(800, 600);


Of course in 2013 everything opens in the same browser window (tab) so again this would be a non-issue.
I personally don’t like not being able to choose how my apps behaves. I also here the same voices from others in my radius.
My thoughts are that the CRM team need to create different themes for different mediums and not impose the tablet/mobile look on office applications.

Cheers



No comments:

Post a Comment