⭕️ 2. Enhance native form: Prevent submission based on emptiness

Previously, I posted a topic about: Exploring the Enhanced Capabilities of Glide’s Native Form, to prevent a form from being submitted based on the visibility of the Hint component to control the Submit button (whether it can be pressed or not) through CSS.

This time, I am adding another method: preventing form submission based on whether the form has number-entry or text-entry components that are filled or empty. This method is simpler because it does not require the assistance of the Hint component or others. This prevention concept might be extended to other components which I will add if needed.

I also include code to add the text “Required” to the input field if the component is empty, especially when directing it to a column in the user table.

/*PREVENT-SUBMIT*/
#page-root:has(.textEntry [data-testid="wf-input"]:empty) [aria-label="Submit"], #page-root:has(.numberEntry label [data-testid="wf-input"][type="number"][value=""]) [aria-label="Submit"] {
    pointer-events: none;
    opacity: 0.4;
}
/*REQUIRED*/
.textEntry:has([data-testid="wf-input"]:empty) label > div:nth-child(2) > div::before {
    content: "Required";
    position: absolute;
    top: 50%;
    padding-left: 15px;
    transform: translateY(-50%);
    color: darkGray;
    opacity: 0.7;
    visibility: visible;
    z-index:999;
}
.numberEntry label:has([data-testid="wf-input"][type="number"][value=""]):not(:focus-within)::before {
    content: "Required";
    position: absolute;
    top: 50%;
    padding-left: 15px; 
    color: darkGray;
    opacity: 0.7;
    visibility: visible;
    z-index:999;
}

Notes:

  1. Assign the class name “textEntry” or “numberEntry” according to the type of component you are using.
  2. The code [aria-label=“Submit”], the word “Submit” needs to be adjusted for different languages, or you can add more than one selector for various languages using a comma to separate them in your selector.

Control Submission Based on On/Off State

For the Switch/Checkbox components, you need to add a container component to apply class names (switch-Comp and check-Box). For the switch location, simply assign the class name directly to the component (location-switch).

/*Checkedbox with Container*/
#page-root:has([data-testid="wire-component-stack-check-Box"]):not(:has([data-testid="wire-component-stack-check-Box"] svg)) [aria-label="Submit"] {
    pointer-events: none;
    opacity: 0.4;
}

/*Switch Component with Container*/
#page-root:has([data-testid="wire-component-stack-switch-Comp"]):not(:has([data-testid="wire-component-stack-switch-Comp"] .peer:checked)) [aria-label="Submit"] {
    pointer-events: none;
    opacity: 0.4;
}

/*Location-switch*/
#page-root:not(:has(.location-switch .peer:checked)) [aria-label="Submit"] {
    pointer-events: none;
    opacity: 0.4;
}
11 Likes

Well done! Bookmarked!

1 Like

Thanks for this!

I used your Hint CSS on a recent native form but combined it with a hide-submit to completely hide the Cancel/Submit buttons. I also have custom Back/Next buttons that steps through the native form and uses your CSS, to make the Next buttons unclickable until the condition is met.

On the last step I unhide the Submit and use your “prevent-submit”.

I’ll try this out too. Makes the native form look like a custom form.

1 Like

I still have one more method and it’s after dinner. :pray:

@Himaladin — Here’s a challenge for you:

Sometimes, in a native form, a choice component ends up being filtered such that no choices meet the filter criteria and thus hides the choice component. However, the choice component is required, so we want to prevent the choice component from hiding. Thoughts?

1 Like

If I understand you correctly, it seems that the component also does not leave a trace in the devtools. Are you suggesting displaying it with another component? Perhaps a method like this can be used: In-app filter message for no matching results? In other words, if this choice component is not found (:not(:has(thisComponent))), then another choice component appears. However, can’t this be done without CSS?

I ended up building a pseudo custom form using temporary Fields user profile table.

1 Like

Hey thats really interesting! So filters only without CSS?
Any chance for a short video/demo :pray:

Yes, maybe a combination with the user table will work. Unfortunately I don’t have a case example of this to study.

Today’s update adds switch and location components based on on-off states to prevent submission.

how to border for choice component?OR Date Component? before click active or data is empty

If you are asking about CSS styling issues rather than a prevent-submission issue, please create a new topic; someone might be able to help you. Meanwhile, I am currently having problems with my computer and cannot answer you at the moment.