fix: argument form submit and suggestionsBrowserKey integration config
Call preventDefault at the start of handleSubmit so failed validation does not trigger a native form submit. Map ascii_sentence inputs to text. Set ascii_sentence on suggestionsBrowserKey test arguments so hyphenated values pass validation. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ad05659e74
commit
f33d764a5f
|
|
@ -27,11 +27,11 @@
|
||||||
{{ choice.title || choice.value }}
|
{{ choice.title || choice.value }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<component v-else :is="getInputComponent(arg)" :id="arg.name" :name="arg.name"
|
<component v-else :is="getInputComponent(arg)" :id="arg.name" :name="arg.name"
|
||||||
:value="(arg.type === 'checkbox' || arg.type === 'confirmation') ? undefined : getArgumentValue(arg)"
|
:value="(arg.type === 'checkbox' || arg.type === 'confirmation') ? undefined : getArgumentValue(arg)"
|
||||||
:checked="(arg.type === 'checkbox' || arg.type === 'confirmation') ? getArgumentValue(arg) : undefined"
|
:checked="(arg.type === 'checkbox' || arg.type === 'confirmation') ? getArgumentValue(arg) : undefined"
|
||||||
:list="(arg.suggestions || getBrowserSuggestions(arg).length > 0) ? `${arg.name}-choices` : undefined"
|
:list="(arg.suggestions || getBrowserSuggestions(arg).length > 0) ? `${arg.name}-choices` : undefined"
|
||||||
:type="getInputComponent(arg) !== 'select' ? getInputType(arg) : undefined"
|
:type="getInputComponent(arg) !== 'select' ? getInputType(arg) : undefined"
|
||||||
:rows="arg.type === 'raw_string_multiline' ? 5 : undefined"
|
:rows="arg.type === 'raw_string_multiline' ? 5 : undefined"
|
||||||
:step="arg.type === 'datetime' ? 1 : undefined" :pattern="getPattern(arg)"
|
:step="arg.type === 'datetime' ? 1 : undefined" :pattern="getPattern(arg)"
|
||||||
|
|
@ -174,7 +174,7 @@ function getInputType(arg) {
|
||||||
return 'checkbox'
|
return 'checkbox'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.type === 'ascii_identifier' || arg.type === 'ascii') {
|
if (arg.type === 'ascii_identifier' || arg.type === 'ascii' || arg.type === 'ascii_sentence') {
|
||||||
return 'text'
|
return 'text'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,7 +252,7 @@ async function validateArgument(arg, value) {
|
||||||
|
|
||||||
// Get the input element to set custom validity
|
// Get the input element to set custom validity
|
||||||
const inputElement = document.getElementById(arg.name)
|
const inputElement = document.getElementById(arg.name)
|
||||||
|
|
||||||
if (validation.valid) {
|
if (validation.valid) {
|
||||||
delete formErrors.value[arg.name]
|
delete formErrors.value[arg.name]
|
||||||
// Clear custom validity message
|
// Clear custom validity message
|
||||||
|
|
@ -322,7 +322,7 @@ function getBrowserSuggestions(arg) {
|
||||||
if (!arg.suggestionsBrowserKey) {
|
if (!arg.suggestionsBrowserKey) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const stored = localStorage.getItem(`olivetin-suggestions-${arg.suggestionsBrowserKey}`)
|
const stored = localStorage.getItem(`olivetin-suggestions-${arg.suggestionsBrowserKey}`)
|
||||||
if (stored) {
|
if (stored) {
|
||||||
|
|
@ -332,7 +332,7 @@ function getBrowserSuggestions(arg) {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Failed to load browser suggestions:', err)
|
console.warn('Failed to load browser suggestions:', err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -340,21 +340,21 @@ function saveBrowserSuggestions() {
|
||||||
for (const arg of actionArguments.value) {
|
for (const arg of actionArguments.value) {
|
||||||
if (arg.suggestionsBrowserKey) {
|
if (arg.suggestionsBrowserKey) {
|
||||||
const value = argValues.value[arg.name]
|
const value = argValues.value[arg.name]
|
||||||
|
|
||||||
// Only save non-empty values for non-checkbox/confirmation/password types
|
// Only save non-empty values for non-checkbox/confirmation/password types
|
||||||
if (value && value !== '' && arg.type !== 'checkbox' && arg.type !== 'confirmation' && arg.type !== 'password') {
|
if (value && value !== '' && arg.type !== 'checkbox' && arg.type !== 'confirmation' && arg.type !== 'password') {
|
||||||
try {
|
try {
|
||||||
const key = `olivetin-suggestions-${arg.suggestionsBrowserKey}`
|
const key = `olivetin-suggestions-${arg.suggestionsBrowserKey}`
|
||||||
const stored = localStorage.getItem(key)
|
const stored = localStorage.getItem(key)
|
||||||
let suggestions = []
|
let suggestions = []
|
||||||
|
|
||||||
if (stored) {
|
if (stored) {
|
||||||
suggestions = JSON.parse(stored)
|
suggestions = JSON.parse(stored)
|
||||||
if (!Array.isArray(suggestions)) {
|
if (!Array.isArray(suggestions)) {
|
||||||
suggestions = []
|
suggestions = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add value if not already present
|
// Add value if not already present
|
||||||
if (!suggestions.includes(value)) {
|
if (!suggestions.includes(value)) {
|
||||||
suggestions.unshift(value) // Add to beginning
|
suggestions.unshift(value) // Add to beginning
|
||||||
|
|
@ -390,11 +390,13 @@ async function startAction(actionArgs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSubmit(event) {
|
async function handleSubmit(event) {
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
// Set custom validity for required fields
|
// Set custom validity for required fields
|
||||||
for (const arg of actionArguments.value) {
|
for (const arg of actionArguments.value) {
|
||||||
const value = argValues.value[arg.name]
|
const value = argValues.value[arg.name]
|
||||||
const inputElement = document.getElementById(arg.name)
|
const inputElement = document.getElementById(arg.name)
|
||||||
|
|
||||||
if (arg.required && (!value || value === '')) {
|
if (arg.required && (!value || value === '')) {
|
||||||
formErrors.value[arg.name] = 'This field is required'
|
formErrors.value[arg.name] = 'This field is required'
|
||||||
// Set custom validity for required field validation
|
// Set custom validity for required field validation
|
||||||
|
|
@ -410,14 +412,12 @@ async function handleSubmit(event) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
event.preventDefault()
|
|
||||||
|
|
||||||
const argvs = getArgumentValues()
|
const argvs = getArgumentValues()
|
||||||
console.log('argument form has elements that passed validation')
|
console.log('argument form has elements that passed validation')
|
||||||
|
|
||||||
// Save values to localStorage for arguments with suggestionsBrowserKey
|
// Save values to localStorage for arguments with suggestionsBrowserKey
|
||||||
saveBrowserSuggestions()
|
saveBrowserSuggestions()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await startAction(argvs)
|
const response = await startAction(argvs)
|
||||||
if (popupOnStart.value && popupOnStart.value.includes('execution-dialog')) {
|
if (popupOnStart.value && popupOnStart.value.includes('execution-dialog')) {
|
||||||
|
|
@ -496,4 +496,4 @@ form {
|
||||||
display: inline;
|
display: inline;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@ actions:
|
||||||
- name: testInput
|
- name: testInput
|
||||||
title: Test Input
|
title: Test Input
|
||||||
description: "This input uses suggestionsBrowserKey"
|
description: "This input uses suggestionsBrowserKey"
|
||||||
|
type: ascii_sentence
|
||||||
suggestionsBrowserKey: test-suggestions-key
|
suggestionsBrowserKey: test-suggestions-key
|
||||||
- name: testInput2
|
- name: testInput2
|
||||||
title: Test Input 2
|
title: Test Input 2
|
||||||
description: "This input shares the same suggestionsBrowserKey"
|
description: "This input shares the same suggestionsBrowserKey"
|
||||||
|
type: ascii_sentence
|
||||||
suggestionsBrowserKey: test-suggestions-key
|
suggestionsBrowserKey: test-suggestions-key
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue