Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix formactions template to consider arguments #144

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

mschoettle
Copy link

Adds id and css_class to the div. Also adds row to the class if the form is supposed to be horizontal.

I removed the inner divs since those seemed to be not used. Let me know if that is incorrect.

Also, let me know if I should add tests for this.

Fixes #143

@JanMalte
Copy link

JanMalte commented Jul 7, 2023

@smithdc1 could this please be merged and a bugfix version be released soon?

@smithdc1
Copy link
Member

smithdc1 commented Jul 7, 2023

Hi All,

I'd like to see a small test added as that seems to be missing at the moment. A minimal layout could be created with the output asserted something like this.

assert parse_form(test_form) == parse_expected("alert.html")

@smithdc1
Copy link
Member

@JanMalte -- do you have time to add a test for this?

@mschoettle
Copy link
Author

Sorry for the delay. I agree that tests would be good so I finally added some.

Copy link
Member

@smithdc1 smithdc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick response.

Just one small comment about field_class. I think that needs adding.

<div class="aab {{ label_class }}"></div>
{% endif %}

<div class="{{ field_class }}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need to add field_class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied all the suggestions but then thought after that field_class might not be appropriate here: Would field_class not be applied to each child field of FormActions?

Consider the following test:

def test_formactions_field_class(self):
        test_form = SampleForm()
        test_form.helper = FormHelper()
        test_form.helper.form_tag = False
        test_form.helper.field_class = "field-class"
        test_form.helper.layout = Layout(
            FormActions(
                Field('email'),
            ),
        )

        print(render_crispy_form(test_form))

Output:

<div
     
    class="mb-3  field-class" 
    > <div id="div_id_email" class="mb-3"> <label for="id_email" class="form-label requiredField">
                email<span class="asteriskField">*</span> </label> <div class="field-class"> <input type="text" name="email" maxlength="30" class="textinput textInput inputtext form-control" required id="id_email"> <div id="hint_id_email" class="form-text">Insert your email</div> </div> </div> </div>

As per field.html the <input> gets wrapped into a div with CSS class field-class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is FormActions used to wrap Fields? The crispy-form docs say...

FormActions: It wraps fields in a

. It is usually used to wrap form’s buttons.

With an example form as per the docs. (please forgive the lack of style on the cancel button).

Main branch:

image

This patch:

image

This therefore looks like a visual regression to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I reverted that change and also brought back the div for label_class to be consistent with the other template packs.

tests/results/test_formactions.html Outdated Show resolved Hide resolved
tests/test_layout_objects.py Outdated Show resolved Hide resolved
tests/test_layout_objects.py Outdated Show resolved Hide resolved
tests/test_layout_objects.py Show resolved Hide resolved
Copy link
Author

@mschoettle mschoettle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: I wasn't able to run pytest after following the README. manage.py is missing. The only way I got it running was by adding it to the root of the project. If this is acceptable I can add it in a separate PR.

<div class="aab {{ label_class }}"></div>
{% endif %}

<div class="{{ field_class }}">
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied all the suggestions but then thought after that field_class might not be appropriate here: Would field_class not be applied to each child field of FormActions?

Consider the following test:

def test_formactions_field_class(self):
        test_form = SampleForm()
        test_form.helper = FormHelper()
        test_form.helper.form_tag = False
        test_form.helper.field_class = "field-class"
        test_form.helper.layout = Layout(
            FormActions(
                Field('email'),
            ),
        )

        print(render_crispy_form(test_form))

Output:

<div
     
    class="mb-3  field-class" 
    > <div id="div_id_email" class="mb-3"> <label for="id_email" class="form-label requiredField">
                email<span class="asteriskField">*</span> </label> <div class="field-class"> <input type="text" name="email" maxlength="30" class="textinput textInput inputtext form-control" required id="id_email"> <div id="hint_id_email" class="form-text">Insert your email</div> </div> </div> </div>

As per field.html the <input> gets wrapped into a div with CSS class field-class.

@mschoettle
Copy link
Author

@smithdc1 Brought this PR up to date with main. Could you please re-review?

Copy link
Member

@smithdc1 smithdc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mschoettle

Thanks for coming back to this! 🎁

I've reviewed again and have added some images of what this looks like. I'm afraid I still think we need to keep field_class. Appreciate your thoughts.

<div class="aab {{ label_class }}"></div>
{% endif %}

<div class="{{ field_class }}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is FormActions used to wrap Fields? The crispy-form docs say...

FormActions: It wraps fields in a

. It is usually used to wrap form’s buttons.

With an example form as per the docs. (please forgive the lack of style on the cancel button).

Main branch:

image

This patch:

image

This therefore looks like a visual regression to me.

@mschoettle
Copy link
Author

@smithdc1 I addressed the requested changes. Could you please look at this again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FormActions ignoring css_class argument
3 participants