I had a code that dynamically creates items and adds them as lookup values. I used CSR but CSR is unavailable on calendar forms (EditForm/NewForm.aspx), so I try to re-write it to vanilla javascript.
I have some form with lookup field pointed to "Customers" ("Customer Name"). And I've added a code that creates new option to this lookup dropdown. Let's pretend I open this NewForm.aspx:
<br/>
<label for="mylookupid">Lookup ID:</label>
<input type="text" id="mylookupid"/><br/>
<label for="mylookuptext">Lookup text:</label>
<input type="text" id="mylookuptext"/><br/><br/>
<input type="button" id="addoption" title="Add Option" value="Add New Option to 'Customer Name' dropdown" /><br />
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script language="javascript" type="text/javascript">
function addOptionToDropdown() {
// lookup dropdown 'Customer Name'
var select = document.querySelector("select[title='Customer Name']");
// will read actual ID and Title from inputs
var option = document.createElement('option');
option.value = jQuery("#mylookupid").val();
option.innerHTML = jQuery("#mylookuptext").val();
// add new option and select it
select.appendChild(option);
option.selected = true;
}
function init() {
jQuery("#addoption").on("click", function () {
addOptionToDropdown();
});
}
_spBodyOnLoadFunctionNames.push("init");
</script>
Then I go to "Customers" list and create new item, Bob:
Now I have 'Bob' item with ID 138:
Ok, now I want to set this item as new lookup choice (my NewForm.aspx does not know about this new item). I enter ID and Title and press my button:
Bob added. But when I save form I get
"Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation."
Is it possible to avoid it(without CSR because I can't use it on Event forms)?




