Pergunta

I'm writing a Google Chrome Extension using a Content Script to add functionality to Google Calendar

When you click a button I created on the page, I then update the Calendar Events "WHERE" input and the "DESCRIPTION" input on the page based on some dynamic content.

Editing these inputs works fine, but when you Save the event, the title and description do not get saved (I'm assuming because I am entering the values via javascript). If I inject the content, and then manually do any keyboard character before saving (literally typing on my keyboard), the title and description get saved.

I have tried triggering all sorts of events on the input after editing the value to trigger whatever dirty flag/event it is looking for, but with no success:

Tried:

input.change();

input.focus.blur();

var e = $.Event('keypress');
e.which = 13; //enter key
input.trigger(e);

I can't see if this is because my javascript is sandboxed, or google is doing something special here. If its because of the sandbox, i'm probably blocked. The only reason I supect google might be doing something special here is that if i edit the value= attribute on the input element, it doesnt change the displayed value, which is odd

<input id=":47" name=":47" type="text" class="textinput" placeholder="Enter a location" autocomplete="off" aria-labelledby=":2t.location-label">

Any help would be greatly appreciated

Foi útil?

Solução

I have found that A) obviously i should apply focus before inserting the value and B) using the document.exeCommand it works correctly

input.focus();
document.execCommand('inserthtml', false, 'New Input Value Yada Yada Yada');
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top