EasyCorp / EasyCorp/EasyAdminBundle

Form stays unsubmitted when fields are disabled and boolean toggles are unchecked

Open Beginner friendly
#7,819 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
4.3k
Forks
1.1k
Avg merge
8d 2h
Merged PRs (30d)
11

Description

Hey guys. I just encountered an interesting behavior. Probably this is related to browser default behaviors.

I have a crud controller edit-form full of disabled fields. Reasons is data imported from another source and I don't want users to modify them. The only editable field I added is an "Active" toggle, which let's back office users decide whether they want to enable or disable the record.

Now issue is: Browsers don't send disabled fields in requests. Same is for unchecked checkboxes. It means, if no fields are sent, Symfony's request is considered "not submitted" and redirects the user back to the edit-form, as if they just reloaded the page.

Maybe a solution could be to always render a hidden field for boolean fields which default to the opposite value?

I can see the following implementation of EasyAdmin's Switch.html.twig:

<span class="{{ css_class }}">
    <input type="checkbox" role="switch" class="ea-switch-input"
        {% if id %}id="{{ id }}"{% endif %}
        {% if name %}name="{{ name }}"{% endif %}
        value="{{ value }}"
        {{ checked ? 'checked' }} {{ disabled ? 'disabled' }} {{ required ? 'required' }}
        {% if ariaLabel %}aria-label="{{ ariaLabel }}"{% endif %}
        autocomplete="off"
        {{ attributes.without('class') }}>
    <span class="ea-switch-track" aria-hidden="true"><span class="ea-switch-thumb"></span></span>
</span>

What if you could add a <input type="hidden" ...> there as well?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the Switch.html.twig implementation shown in the issue and reproduce a form containing only disabled fields plus an unchecked Active toggle. Verify the intended behavior with Symfony request handling; done means the form submits instead of being treated as unsubmitted when the toggle is unchecked.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.