From ba3c8207db2ecddb718fed8c978bf1761e5d6c22 Mon Sep 17 00:00:00 2001
From: Parth Bhattacharya <70539-parthbcharya@users.noreply.drupalcode.org>
Date: Fri, 14 Feb 2025 21:03:05 +0000
Subject: [PATCH] Issue #3498485 by jessebaker, parthbcharya, lauriii,
 callumharrod, bnjmnm: 'false' appears in Page Title when deleting all
 characters

---
 ui/src/components/form/inputBehaviors.tsx |  5 ++++-
 ui/tests/e2e/page-data-form.cy.js         | 10 +++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/ui/src/components/form/inputBehaviors.tsx b/ui/src/components/form/inputBehaviors.tsx
index 129dc40dd8..5171ec944d 100644
--- a/ui/src/components/form/inputBehaviors.tsx
+++ b/ui/src/components/form/inputBehaviors.tsx
@@ -400,12 +400,15 @@ const InputBehaviorsEntityForm = (
 
   const parseNewValue = (e: React.ChangeEvent) => {
     const target = e.target as HTMLInputElement;
-    if (target.value) {
+    // If the target is an input element, return its value
+    if (target.value !== undefined) {
       return target.value;
     }
+    // If the target is a checkbox or radio button, return its checked
     if ('checked' in target) {
       return target.checked;
     }
+    // If the target is neither an input element nor a checkbox/radio button, return null
     return null;
   };
 
diff --git a/ui/tests/e2e/page-data-form.cy.js b/ui/tests/e2e/page-data-form.cy.js
index bb219d2ce0..7c63266b4a 100644
--- a/ui/tests/e2e/page-data-form.cy.js
+++ b/ui/tests/e2e/page-data-form.cy.js
@@ -31,7 +31,8 @@ describe('Page data form', () => {
       .findByLabelText('Title')
       .as('titleField');
     cy.get('@titleField').focus();
-    cy.get('@titleField').type('{selectall}This is a new title');
+    cy.get('@titleField').clear();
+    cy.get('@titleField').type('This is a new title');
     cy.get('@titleField').should('have.value', 'This is a new title');
     cy.get('button[aria-label="Undo"]').should('be.enabled');
     cy.get('button[aria-label="Redo"]').should('be.disabled');
@@ -56,7 +57,8 @@ describe('Page data form', () => {
       .as('heroTitle');
     cy.get('@heroTitle').should('have.value', 'hello, world!');
     cy.get('@heroTitle').focus();
-    cy.get('@heroTitle').type('{selectall}This is a new hero title');
+    cy.get('@heroTitle').clear();
+    cy.get('@heroTitle').type('This is a new hero title');
     cy.wait('@patchPreview');
     // Editing a component field should push that onto the undo state.
     cy.get('button[aria-label="Undo"]').should('be.enabled');
@@ -87,7 +89,9 @@ describe('Page data form', () => {
       .should('have.value', 'XB Needs This For The Time Being');
 
     cy.get('@titleField').focus();
-    cy.get('@titleField').type('{selectall}This is a new title');
+    cy.get('@titleField').clear();
+    cy.get('@titleField').should('have.value', '');
+    cy.get('@titleField').type('This is a new title');
     cy.get('@titleField').should('have.value', 'This is a new title');
     cy.get('button[aria-label="Undo"]').should('be.enabled');
     cy.get('button[aria-label="Redo"]').should('be.disabled');
-- 
GitLab