Add full name to form detector (#622)

This commit is contained in:
Leendert de Borst
2025-02-28 12:40:17 +01:00
parent a82b7d7ce5
commit 451fe98102
4 changed files with 15 additions and 0 deletions

View File

@@ -66,6 +66,10 @@ export function fillCredential(credential: Credential, input: HTMLInputElement)
form.emailConfirmField.value = credential.Email;
triggerInputEvents(form.emailConfirmField);
}
if (form.fullNameField) {
form.fullNameField.value = `${credential.Alias.FirstName} ${credential.Alias.LastName}`;
triggerInputEvents(form.fullNameField);
}
if (form.firstNameField) {
form.firstNameField.value = credential.Alias.FirstName;
triggerInputEvents(form.firstNameField);

View File

@@ -5,6 +5,7 @@ export type FieldPatterns = {
username: string[];
firstName: string[];
lastName: string[];
fullName: string[];
email: string[];
emailConfirm: string[];
password: string[];
@@ -29,6 +30,7 @@ export type GenderOptionPatterns = {
*/
export const EnglishFieldPatterns: FieldPatterns = {
username: ['username', 'login', 'identifier', 'user'],
fullName: ['fullname', 'full-name', 'full name'],
firstName: ['firstname', 'first-name', 'fname', 'name', 'given-name'],
lastName: ['lastname', 'last-name', 'lname', 'surname', 'family-name'],
email: ['email', 'mail', 'emailaddress'],
@@ -55,6 +57,7 @@ export const EnglishGenderOptionPatterns: GenderOptionPatterns = {
*/
export const DutchFieldPatterns: FieldPatterns = {
username: ['gebruikersnaam', 'gebruiker', 'login', 'identifier'],
fullName: ['volledige naam'],
firstName: ['voornaam', 'naam'],
lastName: ['achternaam'],
email: ['e-mailadres', 'e-mail'],
@@ -81,6 +84,7 @@ export const DutchGenderOptionPatterns: GenderOptionPatterns = {
*/
export const CombinedFieldPatterns: FieldPatterns = {
username: [...new Set([...EnglishFieldPatterns.username, ...DutchFieldPatterns.username])],
fullName: [...new Set([...EnglishFieldPatterns.fullName, ...DutchFieldPatterns.fullName])],
firstName: [...new Set([...EnglishFieldPatterns.firstName, ...DutchFieldPatterns.firstName])],
lastName: [...new Set([...EnglishFieldPatterns.lastName, ...DutchFieldPatterns.lastName])],
/**

View File

@@ -428,6 +428,11 @@ export class FormDetector {
detectedFields.push(usernameField);
}
const fullNameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.fullName, ['text'], detectedFields);
if (fullNameField) {
detectedFields.push(fullNameField);
}
const firstNameField = this.findInputField(wrapper as HTMLFormElement | null, CombinedFieldPatterns.firstName, ['text'], detectedFields);
if (firstNameField) {
detectedFields.push(firstNameField);
@@ -464,6 +469,7 @@ export class FormDetector {
usernameField,
passwordField: passwordFields.primary,
passwordConfirmField: passwordFields.confirm,
fullNameField,
firstNameField,
lastNameField,
birthdateField,

View File

@@ -7,6 +7,7 @@ export type FormFields = {
passwordConfirmField: HTMLInputElement | null;
// Identity fields
fullNameField: HTMLInputElement | null;
firstNameField: HTMLInputElement | null;
lastNameField: HTMLInputElement | null;