Forum Discussion

PrakashMurali97's avatar
PrakashMurali97
Qrew Trainee
20 days ago

Required Fields Not Validating on Edit Form with Custom Save Button

I have required fields in one of my forms. I'm using a custom button to save the form. When I click the "Save" button, it checks for the required fields in the Add Form, but it doesn't perform the validation in the Edit Form.

How can I ensure that required field validation works on the Edit Form as well when using the custom save button?

This is the custom button formula:

// Define the container style
var text container = 
    "display: flex;" &              // Use flexbox layout for arranging children
    "justify-content: center;" &    // Center all child elements horizontally
    "gap: 17px;";                   // Add space between child elements

// Define the subcontainer style
var text subcontainer = 
    "display: flex;" &              // Use flexbox layout for subcontainer
    "justify-content: center;";     // Center all child elements horizontally

// Define the button container style
var text buttonContainer = 
    "width: 130px;" &               // Set fixed width for the button container
    "display: flex;" &              // Use flexbox layout
    "flex-direction: column;" &     // Stack buttons vertically
    "gap: 10px;" &                  // Add space between buttons
    "padding: 5px 3px;" &           // Add inner spacing (5px top/bottom, 3px left/right)
    "border-radius: 8px;";          // Round the container's corners

// Define the orange button style
var text orangebutton = 
    "border-radius: 40px;" &        // Fully round the button's edges
    "color: #ffffff;" &             // Set the button's text color to white
    "background-color: #f8761f;" & // Set the button's background to orange
    "font-family: Roboto, sans-serif;" & // Use Roboto font with sans-serif fallback
    "font-weight: 700;" &           // Make the text bold
    "font-size: 12px;" &            // Set the text size
    "padding: 12px 40px;" &         // Add spacing inside the button (12px vertical, 40px horizontal)
    "display: inline-block;" &      // Ensure the button behaves like an inline-block element
    "line-height: 20px;" &          // Set the line height for text
    "text-decoration: none;" &      // Remove underline from the button text
    "text-align: center;";         // Center the text inside the button
   
// Define the black button style
var text blackbutton = 
    "border-radius: 40px;" &        // Fully round the button's edges
    "color: #ffffff;" &             // Set the button's text color to white
    "background-color: #252525;" & // Set the button's background to black
    "font-family: Roboto, sans-serif;" & // Use Roboto font with sans-serif fallback
    "font-weight: 700;" &           // Make the text bold
    "font-size: 12px;" &            // Set the text size
    "padding: 12px 40px;" &         // Add spacing inside the button (12px vertical, 40px horizontal)
    "display: inline-block;" &      // Ensure the button behaves like an inline-block element
    "line-height: 20px;" &          // Set the line height for text
    "text-decoration: none;" &      // Remove underline from the button text
    "text-align: center;";        // Center the text inside the button
    

// Define the Record ID or placeholder if not available
var text rid = 
    If([Record ID#] > 0,            // Check if a Record ID exists
        ToText([Record ID#]),       // Use the existing Record ID
        "%%rid%%"                   // Placeholder for new records
    );

// Define the close window URL
var text closewindow = URLRoot() & "db/" & AppID() & "?a=dbpage&pageid=11"; // URL to redirect to page 11 after an action, which closes the popup page

// Construct the Submit URL
var text Submit = 
    URLRoot() & "db/" & Dbid() &                // App root and database ID
    "?a=API_EditRecord&rid=" & $rid &           // API call to edit a record using Record ID
    "&_fid_23=" & URLEncode("Pending FP&A Approval") & // Update status field with "Pending FP&A Approval"
    "&_fid_25=2" &                              // Update field 25 with value 2
    "&_fid_26=1" &                              // Update field 26 with value 1
    "&rdr=" & URLEncode($closewindow);          // Redirect to the close window URL after editing

// Construct the HTML structure
"<div style='" & $container & "'>" &           // Outer container with flexbox layout
    "<div style='" & $subcontainer & "'>" &    // Subcontainer centered within the outer container
        "<div style='" & $buttonContainer & "'>" & // Button container for Cancel button
            "<a  style='" & $blackbutton & "' href='" & $closewindow & "'>Cancel</a>" & // Cancel button styled as black
        "</div>" & 
        If([Payment Request Status] = "New",   // Conditional logic for Submit or Save button
            "<div style='" & $buttonContainer & "'>" & // Button container for Submit button
                "<a class='SaveBeforeNavigating' data-replaceRid=true style='" & $Orangebutton & "' href='" & $Submit & "'>Submit</a>" &
            "</div>",
            "<div style='" & $buttonContainer & "'>" & // Button container for Save button
                "<a class='SaveBeforeNavigating' data-replaceRid=true style='" & $Orangebutton & "' href='" & $closewindow & "'>Save</a>" &
            "</div>"
        ) &
    "</div>" & 
"</div>"

This is the code page content:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script>
  window.close();
</script>
<body>

</body>
</html>

Any help would be greatly appreciated!