Reputation: 2595
In the options.html
i have an input, where user fill their API keys, like
<label>
Input your API Key
<input type="text" id="wptk">
</label>
In the options.js
there is a piece of code, which is saving it into storage, like with
function save_options() {
var api = document.getElementById('wptk').value;
chrome.storage.sync.set({
savedApi: api,
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'OK! API Key saved!';
setTimeout(function() {
status.textContent = '';
}, 10000);
});
}
document.getElementById('save').addEventListener('click', save_options);
document.getElementById('wptk').value = api
It works everything, no problem. But, nevertheless the key is saved, if user looks at options twice, the form (input) is empty.
How could i display the string in the form always after it was saved?
Upvotes: 1
Views: 31
Reputation: 3469
You will need to get saved value of savedApi
from storage and set as your field value. See below example code.
function restore_options() {
chrome.storage.sync.get({"savedApi": ''}, function(items) {
document.getElementById('wptk').value = items.savedApi;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
Upvotes: 1