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

HiddenField shows up in the HTML form of the web browsable API page #2410

Closed
lgp171188 opened this issue Jan 13, 2015 · 10 comments
Closed

HiddenField shows up in the HTML form of the web browsable API page #2410

lgp171188 opened this issue Jan 13, 2015 · 10 comments
Labels
Milestone

Comments

@lgp171188
Copy link

lgp171188 commented Jan 13, 2015

I have a model with a foreign key reference to the User model called 'user'. In my serializer class, which is a sub-class of ModelSerializer, I have overridden the default field created by ModelSerializer and set it to:

user = serializers.HiddenField(default=serializers.CurrentUserDefault())

When displaying the fields in the API response, this field is indeed hidden, but in the web browsable API page, the HTML form shows a textbox for the user field which is supposed to be hidden.

Here is my serializer definition:

class CategorySerializer(serializers.ModelSerializer):
    user = serializers.HiddenField(default=serializers.CurrentUserDefault())
    class Meta:
        model = Category
        fields = ('name', 'description', 'created', 'modified','user')

Please see the screenshot illustrating the HTML form with an input for the hidden field.

hiddenfield shown in html form

I am totally new to Django REST Framework, so sorry if I haven't RTFM and raised this issue.

@lgp171188
Copy link
Author

lgp171188 commented Jan 13, 2015

I am using version 3.0.3

@jpadilla
Copy link
Member

jpadilla commented Jan 13, 2015

Not sure if intentional, but HiddenFields aren't handled in HTMLFormRenderer.

@tomchristie
Copy link
Member

tomchristie commented Jan 13, 2015

Yup looks valid to me.

@tomchristie tomchristie added this to the 3.0.4 Release milestone Jan 13, 2015
@tomchristie
Copy link
Member

tomchristie commented Jan 13, 2015

Thanks for raising this.

@jpadilla
Copy link
Member

jpadilla commented Jan 13, 2015

@tomchristie submitting a fix...

@lgp171188
Copy link
Author

lgp171188 commented Jan 13, 2015

This could be misleading because I tried to fill in the username of some other user in the form field to see if I could create a category owned by that user. But it created with the user as the currently logged in user.

@tomchristie
Copy link
Member

tomchristie commented Jan 13, 2015

This could be misleading

Agreed - it is misleading yup. We def shouldn't be displaying the field - it won't be being used.

@rubendura
Copy link
Contributor

rubendura commented Feb 2, 2015

Is this really fixed? I have updated DRF to 3.0.4 but my hidden fields keep appearing as before for some reason. I've already checked that the changes from the commit closing this issue have been applied, so I have no idea what's wrong with my environment.

@lgp171188
Copy link
Author

lgp171188 commented Feb 14, 2015

Yes, I can confirm that this fix does not work.

@jpadilla
Copy link
Member

jpadilla commented Feb 20, 2015

Closed via #2580

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

No branches or pull requests

4 participants