-
Notifications
You must be signed in to change notification settings - Fork 51
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
Remember FlexibleImageWidget choice on form redisplay #3681
base: main
Are you sure you want to change the base?
Remember FlexibleImageWidget choice on form redisplay #3681
Conversation
hx-include="[id='values-{{ widget.name }}']" | ||
> | ||
{% if widget.attrs.current_value %} | ||
<option value="{{ widget.attrs.current_value.image.pk }}">{{ widget.attrs.current_value }}</option> | ||
<option value="{{ widget.attrs.current_value.pk }}">{{ widget.attrs.current_value.title }}</option> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my understanding: we don't actually use the value
of this anywhere, do we? Could it then just be left empty or set to one of the two widget choice types below (depending on the type)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value is sent on submission in edit views (where the image is already saved in database) and in form redisplay upon validation error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the change in Add WidgetChoice for selected image for semantic consistency
It is not much change but semantically makes more sense instead of printing the pk value without using it anywhere.
Image.objects.filter(pk=current_value).exists() | ||
or UserUpload.objects.filter(pk=current_value).exists() | ||
elif ( | ||
widget_name == WidgetChoices.IMAGE_SELECTED.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the condition will work anyway without checking for widget_name
value, but it is more robust to check for it.
closes #3558