Skip to content

Commit

Permalink
add reset button
Browse files Browse the repository at this point in the history
  • Loading branch information
keldenl committed Mar 22, 2023
1 parent cf2a2d5 commit a3dd41f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions bin/web/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,11 @@ ${fields}
promptSelect.value = initialPrompt.value;
input.textContent = initialPrompt.value;
// Listen to change event on the dropdown
promptSelect.addEventListener('change', () => {
// Update the input text with the selected prompt value
const handlePromptChange = () => {
const selectedPromptValue = promptSelect.value;
const currentInputValue = input.textContent;
// Update the input text with the selected prompt value
input.textContent = selectedPromptValue;
// Move the cursor to the first instance of ">PROMPT" and select only the word ">PROMPT"
Expand All @@ -305,8 +304,22 @@ ${fields}
// Focus the input
input.focus();
}
promptSelect.addEventListener('change', handlePromptChange);
// Create a Reset button
const resetButton = document.createElement('button');
resetButton.textContent = 'Reset';
// Append the Reset button to the same container as the dropdown
promptSelect.parentNode.appendChild(resetButton);
resetButton.addEventListener('click', (e) => {
e.preventDefault() // Prevent form from submitting
handlePromptChange()
});
})
.catch(error => {
console.error('Error loading prompts:', error);
Expand Down

0 comments on commit a3dd41f

Please sign in to comment.