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

Validation Error Placement for List Editable Fields #381

Open
afsangujarati93 opened this issue May 11, 2024 · 0 comments
Open

Validation Error Placement for List Editable Fields #381

afsangujarati93 opened this issue May 11, 2024 · 0 comments

Comments

@afsangujarati93
Copy link

This isn't directly an issue with unfold, but more a request or help with a UI issue I am facing.

I have enabled list editable on one of my django admin to allow user update the min and max value. I have set a validation in place to make sure that min is not greater than max. The validation works as expected. However, I am not really happy with the way the message is displayed.

So currently as seeing in the screenshot, the error message appears right above the field which messes up the alignment of the table. The column with error becomes wider than the others and it's not even highlighted with red.

image

What I am trying to achieve instead is to show the error on the top of the page like
Please correct the errors below.
Min value cannot be greater than max value

and simply have the errored field highlighted with red border.

It would be nice to make this part of the unfold package. However, if not, what is the best way to achieve this?

I tried overriding the is_valid function in my CustomModelForm but I can't add the messages there since I don't have access to the request object. Anything I tried to pass the request object was in vain.

class CustomModelForm(forms.ModelForm):
           
    class Meta:
        model = MyModel
        fields = '__all__' 
        
    def is_valid(self):
        if 'min_quantity' in self._errors:
            # messages.error(self.request, self._errors["min_quantity"])
            print("Handling a specific validation error for 'min'")
            del self._errors['min_quantity']
    
        super().is_valid()
@afsangujarati93 afsangujarati93 changed the title Highlight list editable validation error Validation Error Placement for List Editable Fields May 11, 2024
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

No branches or pull requests

1 participant