fix(setting-model): support field-level autoComplete to suppress browser autofill (#17559)

This commit is contained in:
chanx
2026-07-30 16:50:31 +08:00
committed by GitHub
parent 5d76b0b96c
commit 6fb6b9e06b
4 changed files with 25 additions and 1 deletions

View File

@@ -93,6 +93,14 @@ export interface FormFieldConfig {
labelClassName?: string;
className?: string;
disabled?: boolean;
/**
* HTML `autocomplete` attribute forwarded to the underlying `<input>`.
* Use `'new-password'` to suppress browser autofill — Chrome ignores
* `'off'` on forms that contain a password field (treats them as login
* forms), so `'new-password'` is the reliable value for autofill-prone
* fields like api_key / instance_name / base_url / group_id.
*/
autoComplete?: string;
}
// Component props interface
@@ -613,6 +621,7 @@ export const RenderField = ({
type={field.type}
placeholder={field.placeholder}
disabled={field.disabled}
autoComplete={field.autoComplete}
/>
</div>
);

View File

@@ -32,6 +32,7 @@ export const GenericApiKeyConfig: ProviderConfig = {
required: true,
placeholder: 'instanceNameMessage',
tooltip: 'instanceNameTip',
autoComplete: 'new-password',
validation: { message: 'instanceNameMessage' },
},
{
@@ -40,6 +41,7 @@ export const GenericApiKeyConfig: ProviderConfig = {
type: FormFieldType.Password,
required: true,
placeholder: 'apiKeyMessage',
autoComplete: 'new-password',
validation: { message: 'apiKeyMessage' },
},
{
@@ -64,6 +66,7 @@ export const GenericApiKeyConfig: ProviderConfig = {
return 'openaiBaseUrlPlaceholder';
},
shouldRender: 'showBaseUrl',
autoComplete: 'new-password',
},
{
name: 'group_id',
@@ -71,6 +74,7 @@ export const GenericApiKeyConfig: ProviderConfig = {
type: FormFieldType.Text,
required: false,
shouldRender: 'showGroupId',
autoComplete: 'new-password',
},
],
verifyTransform: (values) => ({

View File

@@ -209,6 +209,7 @@ export const useProviderFields = ({
value: o.value,
})) as any,
defaultValue: field.defaultValue,
autoComplete: field.autoComplete,
validation,
shouldRender: resolveShouldRender(field.shouldRender),
// In viewMode, only the model-related fields are editable.
@@ -245,7 +246,11 @@ export const useProviderFields = ({
placeholder={placeholderText}
/>
) : (
<Input {...fieldProps} placeholder={placeholderText} />
<Input
{...fieldProps}
placeholder={placeholderText}
autoComplete={field.autoComplete}
/>
);
},
};

View File

@@ -85,6 +85,12 @@ export interface FieldConfig {
options?: SelectOption[];
/** Default value */
defaultValue?: any;
/**
* HTML `autocomplete` attribute forwarded to the underlying `<input>`.
* Use `'new-password'` to suppress browser autofill (Chrome ignores
* `'off'` on forms containing a password field).
*/
autoComplete?: string;
/**
* Validation rules.
* `message` is treated as an i18n key by the ProviderModal and translated