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

CheckboxInput does not display "this field is required" error #91

Closed
XeonZenn opened this issue May 5, 2021 · 2 comments · Fixed by #92
Closed

CheckboxInput does not display "this field is required" error #91

XeonZenn opened this issue May 5, 2021 · 2 comments · Fixed by #92

Comments

@XeonZenn
Copy link

XeonZenn commented May 5, 2021

Update this method to fix it.

    def get_checkbox_classes(self):
        """Return CSS classes for checkbox."""
        classes = ["form-check"]
        if self.checkbox_style == "switch":
            classes.append("form-switch")
        if self.checkbox_layout == "inline":
            classes.append("form-check-inline")
        if self.field_errors:
            classes.append(self.error_css_class)
        elif self.field.form.is_bound:
            classes.append(self.success_css_class)
        return merge_css_classes(*classes)

if it was me, I would add a method like this to make getting valid/invalid easier:

    def get_valid(self):
        if self.field_errors:
            return self.error_css_class
        elif self.field.form.is_bound:
            return self.success_css_class
        return None # or return '' for concatenation
@dyve
Copy link
Member

dyve commented May 6, 2021

That's not all there is to it, the error message also has to go inside the form--check class.

See https://getbootstrap.com/docs/5.0/forms/validation/#server-side

<div class="form-check">
    <input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheck3" aria-describedby="invalidCheck3Feedback" required>
    <label class="form-check-label" for="invalidCheck3">Agree to terms and conditions</label>
    <div id="invalidCheck3Feedback" class="invalid-feedback">You must agree before submitting.</div>
</div>

@XeonZenn
Copy link
Author

XeonZenn commented May 6, 2021

Recent change fixed issue, Good Job!

@XeonZenn XeonZenn closed this as completed May 6, 2021
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 a pull request may close this issue.

2 participants