I have a page that is using SP.UI.ModalDialog.showModalDialog()
to open a NewForm for a list. In the open code I'm passing some values in the args options property as described in this documentation.
The new form is using jslink/client-side rendering to do a couple of things. One of which is assign a choice column if the value has been passed through the arguments.
I've tried both of these lines that I've found in various searches:
args = SP.UI.ModalDialog.get_childDialog().get_args() || {};
args = commonModalDialogGetArguments() || {};
Either one seems to work -- sometimes. Frequently it doesn't return any value. The times it doesn't work I can check in my debugger and if I run the code again or reload the iframe it then works. So I think it is pretty clearly a timing issue.
Edit Additional information
In the csr I've assigned a renderer to a dropdown choice column. The new form can be opened from the regular list (in which case there would be no arguments and the user will need to make a selection) or from my custom page (where the argument is passed). If there is an argument then the custom renderer sets the selected value and makes the drop down disabled.
I had also tried in my custom renderer adding a callback to wait until the body was loaded like this.
var $control = $(getSPField(ctx));
var id = $control.find('select').attr('id');
SP.SOD.executeOrDelayUntilEventNotified(function(){
var args = commonModalDialogGetArguments() || {};
if(args.hasOwnProperty('choiceInfo')){
var $select = $('[id="'+id+'"]);
$select.prop('disabled',true);
$select.find('option')
.removeAttr('selected')
.filter('[value='+choiceInfo.Id+']')
.attr('selected',true);
}
$select.trigger('change');
}, 'sp.bodyloaded')
return $control.prop('outerHTML');
But even after everything was loaded the choice information passed through the arguments wasn't always available.
How can I wait to render the form until after the arguments are properly passed?