This question is related to an earlier question I posted, but did not get an answer on, so I am attempting a different approach.
To summarize: My goal is to set a people picker value to the current user when completing the New Form.
In my previous question, I was trying to use the SPServices function $().SPServices.SPFindPeoplePicker
, however, it would seem that this function does not work for SP2013 forms, so I am working on an alternative.
I am able to set the value of the People Picker field to the current user via the following:
var PickerTitle = "Assigned To";
var currUser = $().SPServices.SPGetCurrentUser({ fieldName: "Title" });
$('input[title="' + PickerTitle + '"]').val(currUser).attr('size', 40);
$('div[title="' + PickerTitle + '"] span.ms-helperText').hide();
However, unlike SP2007, SharePoint does not auto-resolve the People Picker values on save, so unless the user selects the field and manually resolves the name, the value is erased.
I have been pulling out my hair trying to trigger the validation programmatically, but have had no luck. I have noticed that SharePoint will resolve the field if you select it, then hit Tab
, however, I have not been able to force this same trigger via a jQuery event.
// I've tried 'keydown', 'keypress', 'keyup'
var e = jQuery.Event("keydown");
e.which = 9; // 'Tab' keycode
$('input[title="' + PickerTitle + '"]').trigger(e);
Unfortunately, I'm not good enough with Dev Tools to pick that apart to see exactly where the trigger is occurring. Has anybody else been able to determine what exactly is triggering the People Picker validation function and been able to trigger it using JavaScript/jQuery?