javaScript - changing values of location input field on google calendar - javascript

As part of a chrome extension for Google calendar I develop, I want to change the "Add location" input field on a google calendar meeting event (https://calendar.google.com/calendar/b/0/r/eventedit?tab=mc).
So far I've tried the following:
let locationInputField = document.querySelector('[aria-label="Location"]');
locationInputField.value = 'Meeting Place';
locationInputField.dispatchEvent(new Event("input", { bubbles: true }));
Although the value does change, once I save the meeting event the location text ('Meeting Place') is not saved and remains empty.
I've searched for additional optional solutions and also tried using .focus() and .select() but no success there also.
Appreciate your help.
Thanks!

Related

UnhandledPromiseRejectionWarning: Field was not found by text|CSS|XPath

I am very new to coding and I am stuck at a place where I am trying to add some text to a field. The code is written in Javascript and we use Puppeteer as a helper. When I try to click on the field with the same locator, it clicks just fine, even when clearing the field, it works fine. The only issue is happening when I am trying to fill the field, at that time it is not able to find that field with the locator specified, not sure what is going on there.
Here is the code and the run results. In the code, after the pause statement, it is failing.
// View Trial Level Form
clinicalTrialsDashboard.openATrialLevelForm(common.trialLevelFormEditAccess);
within(patientInteraction_po.fullPageModalHeader, () => {
I.dontSeeElement(patientInteraction_po.formSettingsBtn);
I.seeElement(patientInteraction_po.auditHistoryBtn);
I.dontSeeElement(patientInteraction_po.queryModeBtn);
I.dontSeeElement(patientInteraction_po.printBtn);
I.dontSeeElement(patientInteraction_po.investigatorFlagBtn);
I.seeElement(patientInteraction_po.closeForm);
I.seeElement(patientInteraction_po.saveForm);
I.dontSeeElement(patientInteraction_po.saveAndComplete);
//I.fullyClearField(patientInteraction_po.trialLevelFormInput);
I.pause();
I.fillThisField(patientInteraction_po.trialLevelFormInput, 'dddd');
I.waitClick(patientInteraction_po.saveForm);
I.waitForHideForLongTime(common_po.loadingSpinner);
I.see(common.alertMessage);
I.see('Trial Level Form Saved');
I.waitClick(common.okayBtn);
});
Result:
I.
I fill field {"css":".scheduled-form-display [data-c^="form-question"] [data-i*="input-element"]"}, "dddd"
(node:11479) UnhandledPromiseRejectionWarning: Field "{"css":".scheduled-form-display [data-c^="form-question"] [data-i*="input-element"]"}" was not found by text|CSS|XPath
Thanks.

Trouble sending JavaScript into <input type="date"> calendar

Goal: Attempting to automate a calendar on Chrome using Selenium(Python + behave).
The issue: The date is only being set when actually clicked through the calendar. Passing a value via JavaScript is not working.
Note: According to docs the inputs should allow users to send input in with keys by default but that doesn't even work. It does not accept keyboard input at all.
Problem Walkthrough
This is the original input fields. The div class they are contained in is inside a #shadow-root
(open):
Ignoring the Python. I will try and change the values with some simple JavaScript in the Chrome Dev Tools console:
x = document.querySelector("#class > something").shadowRoot.querySelector("div > div > input[type=date]:nth-child(5)") #Select input for From Date
x = "2022-05-12"
y = document.querySelector("#class > something").shadowRoot.querySelector("div > div > input[type=date]:nth-child(5)") #Select input for To Date
y = "2022-06-12"
After sending in the new values and clicking search. It does not recognize the values as being entered:
However, when manually selected through the calendar:
The dates are accepted and as inputs:
The HTML for the calendar is:
<input type="date" min="2022-01-01" max="2022-07-19">
Clearly. The JavaScript alone does not seem to be enough. If you use the same method above on this calendar it will work. However, on the calendar I am attempting this JS method will not work for some reason. Also, I cannot get Selenium to click and open the calendar on its own for some odd reason.
Solution: Manually trigger the event (Source)
let element = document.getElementById(id);
element.dispatchEvent(new Event("change")); // or whatever the event type might be
dispatchEvent() Documentatio
Event() Documentation

Javascript / MS Dynamics CRM 2016: Changing value of option set field using confirm box

I have an option set field in Dynamics CRM that has two values: "In Progress" (default) and "Completed". Using JavaScript, I want to issue a confirm box that triggers during the field event OnChange. The confirm box warns the user that if the user has selected "Completed" it will lock all the other fields in the record.
Anyway, I wrote my code such that the confirm box will set the value of the option set. For some reason, it is not changing the values of the field. If the user clicks "Completed" and when the user clicks 'Cancel' in the confirm box to confirm and validate, it would still set the field value to "Completed". Any reason why it would not set the field values? Here is my code:
function confirmTaskStatus() {
if (Xrm.Page.getControl("moc_taskstatus").getDisabled()){
var taskStatusValue;
var message = "Do you want to set this Task to Completed?
You cannot edit, change or add anything to the Project Task fields
once it is set to Completed";
if (confirm(message) == true) {
taskStatusValue = 223770000; // Display Label = "Completed"
Xrm.Page.getControl("moc_taskstatus").setDisabled(true);
} else {
taskStatusValue = 223770001; // Display Label = "In Progress"
}
Xrm.Page.getAttribute("moc_taskstatus").setValue(taskStatusValue);
}
}
function saveTaskStatus() {
window.setTimeout(confirmTaskStatus, 1000);
}
Have mercy on me; I'm still quite new to scripting and Dynamics CRM.
It looks like the control is disabled (by looking at your code snippet).
Disabled attributes SubmitMode is set to false, meaning, CRM will ignore any updates to the attribute unless you force CRM to save it by calling SetSubmitMode after the value is updated.
Xrm.Page.getAttribute("moc_taskstatus").setValue(taskStatusValue);
Xrm.Page.getAttribute("moc_taskstatus").setSubmitMode('always');

Add a event to full calendar from custom list

I have a hard time to understand how the full calendar plug in works if you want to add a new event.
Every example i have seen is hard coded events, not from textboxes.
I have a custom list where i can add new courses (making a course catalog), what i want with my calendar is that the events that is in the custom list will be showing in the calendar to, after the right date (from a textbox).
Does anyone know how to connect a custom list to a fullcalendar? So when a new event is added in the custom list, it also will be added into the full calendar!
will be really glad if someone could give me an example.
Doing it with javascript!
var createinfo = SP.ListCreationInformation();
var newtask = list.addItem(createinfo);
newtask.set_item('Kursnamn', $('#TextKursnamn').val());
newtask.set_item('Malgrupp', $('#TextMalgrupp').val());
newtask.set_item('Forkunskapskrav', $('#TextForkunskapskrav').val());
newtask.set_item('Matrielkrav', $('#TextMatriellkrav').val());
newtask.set_item('Omfattning', $('#SelectOmfattning').val());
newtask.set_item('Kursledare', $('#TextKursledare').val());
newtask.set_item('Telefonnr', $('#TextTelefonnummer').val());
newtask.set_item('Email', $('#TextEmail').val());
newtask.set_item('Startdatum', $('#TextStartdatum').val());
newtask.set_item('Slutdatum', $('#TextSlutdatum').val());
newtask.set_item('SistaAnmalninsgdag', $('#TextSistaanmalningsdag').val());
newtask.set_item('Fritext', $('#TextInformation').val());
newtask.update();
clientContext.load(newtask);
clientContext.executeQueryAsync(success_Createlist, onFail);
//And the calendar is just empty right now
$('#calendar').fullCalendar({
});

Jquery Autocomplete remembers the previous selection

The requirement is to display autocomplete addresses based on the region selected. The Jquery autocomplete is called everytime the region changes. I am getting the correct autocomplete addresses based on the region. But along with the new address list, I also get the address list for previously selected regions.
To solve this problem, I used - $("#address).removeData('events').autocomplete(...)
This solves the problem. But a new problem is introduced now! The scrolling in the autocomplete list does not work properly, items are skipped on pressing down arrow key/up arrow key.
Here is the code snippet:
$("#address).removeData('events').autocomplete({
serviceUrl : 'mysource',
minChars : 2,
params : {
region : selectedRegion
},
noCache : true,
width : 350,
maxHeight : 170,
onSelect : function (value) {
...
...
}
});
Can somebody suggest me the correct approach? I am using jquey.autocomplete-min.js
If youre getting an additional appearing alongside jquery's autocomplete list, it may be an issue with your browser trying to autocomplete the input.
trying adding the autocomplete="off" attribute to the input field you're autocompleting
As mentioned in this answer the issue might not be with your code snippet but with browser http caching in general.
Well, the following worked like a charm to me
var ac = $("#address").autocomplete();
The next time, the region is changed, instead of calling autocomplete()
again, I just do this -
ac.setOptions({ params:{ region : selectedRegion}});
This updates the existing call with new region. I will no more see autocomplete suggestions for the previous selections.

Categories

Resources