Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Double InputHidden rendering #505

Open
nikolaysm opened this issue May 4, 2021 · 2 comments
Open

Double InputHidden rendering #505

nikolaysm opened this issue May 4, 2021 · 2 comments

Comments

@nikolaysm
Copy link

Form:

class ContactForm(ModelForm):
    scope_prefix = 'contact_data'
    form_name = 'contact_form'

    layout = Layout(
        Row('name', 'function'),
        Row('primary', 'user_pwd')
    )

    class Meta:
        model = Contact
        fields = ('name', 'function','primary', 'user_pwd')

    def __init__(self, *args, **kwargs):
        super(ContactForm, self).__init__(*args, **kwargs)

        if self.instance.pk:
            self.fields["user_pwd"].disabled = True
            if self.initial.get("primary"):
                self.fields["primary"].disabled = True
        else:
            # self.fields["user_pwd"].widget = forms.HiddenInput()
            self.fields["user_pwd"].widget.attrs["type"] = "hidden"
            self.fields["user_pwd"].label = ""

Output:

image

@kmmbvnr
Copy link
Collaborator

kmmbvnr commented May 4, 2021

Mm, yep, if field is present in the layout, it rendered in the desired by layout place, and the hidden form fields rendered separately.

I'm not sure should it be fixed or not. You can make the layout as dynamic @property to overcome this

@nikolaysm
Copy link
Author

nikolaysm commented May 4, 2021

Mm, yep, if field is present in the layout, it rendered in the desired by layout place, and the hidden form fields rendered separately.

I'm not sure should it be fixed or not. You can make the layout as dynamic @property to overcome this

@property is a great solution. Ok, I didn't think about it at all.

Thanks.

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

No branches or pull requests

2 participants