'Are "required" HTML fields not enforced on Django Admin intermediate pages?

I have the following abbreviated HTML for an intermediate Django admin page:

<!DOCTYPE html>
{% extends base_url %}
{% block content %}
<form action="" method="post">
    ...
    <select name="my_name" id="my_id" required>
        <option disabled selected> --- </option> <br />
    ...
    </select>
    ...
    <input type="hidden" name="action" value="my_action" />
    <input type="submit" name="apply" value="Update" />
</form>
{% endblock %}

However, my required attribute does not seem to work, and clicking "Update" submits the form even if no selection has been made.

Am I missing something special about how Django builds intermediate pages?

Happy to provide more code if needed, just removed most of it and replaced with ... for brevity's sake.

Edit: I was able to sidestep the issue by raising an error message if my field wasn't filled out, but that seems messier since it kicks the user back to the Admin page each time:

is_valid_form = 'my_id' in request.POST

if not is_valid_form:
    fail_message = (
        "Error: All fields are required.")
        admin_page.message_user(
            request, fail_message, messages.ERROR)
        return HttpResponseRedirect(request.get_full_path())


Solution 1:[1]

You can make separate methods/functions for each action. Then inside the switch statement, you can call these methods. But if you want to avoid the switch statement, you can use Enums for different cases for example. So it would look something like this:

int f1(int arg1, int arg2...) {
    //do something
}

void f2(int arg1, int arg2...) {
    //do something
}

public static void main() {
    switch(statement){
        case 0:
            f1();

            break;

        case 1:
            f2();

            break;
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TCoder12