GithubHelp home page GithubHelp logo

Comments (8)

gregmuellegger avatar gregmuellegger commented on May 26, 2024

Hm that's really a tricky issue I haven't thought of yet. We'll definitely will need to find a solution. But I'm not sure if not using the required attribute is the right one.

For now you can work around this issue by overwriting the floppyforms/attrs.html template:

{% for name, value in attrs.items %}{% if name != "required" %} {{ name }}{% if value != True %}="{{ value }}"{% endif %}{% endif %}{% endfor %}

from django-floppyforms.

carljm avatar carljm commented on May 26, 2024

HTML5 browser-side required validation is a much nicer UX than having to submit the form before seeing the error; -1 to eliminating the required attribute from the floppyforms widget templates.

The easiest solution here is to just put the empty form outside the HTML <form> tag, then the browser will ignore it.

An even nicer solution (IMO) is to wrap the empty-form HTML in a <script type="text/html"> (rather than a <div style="display: none;">); then the browser will neither display nor interpret the empty-form HTML in any way. This does require some change to the JS used for dynamic formsets, as the empty-form HTML will be available as a single HTML string rather than as DOM nodes.

from django-floppyforms.

gregmuellegger avatar gregmuellegger commented on May 26, 2024

@carljm I totally like your pragmatic approach here, which works in all cases where you want to use JS.
But unfortunatelly this issue is not solved totally then :( django has the extra parameter for formsets to include new, empty forms that can be filled in.

from django-floppyforms.

brutasse avatar brutasse commented on May 26, 2024

Maybe we could just document the issue and tell people to use <form novalidate> when they have optional formsets? This obviously disables browser validation but it seems a bit saner than manipulating extra empty forms to mark them as not required.

from django-floppyforms.

gregmuellegger avatar gregmuellegger commented on May 26, 2024

+1, it doesn't require JS either.

And if you have JS enabled, one could implement a $('.empty-form :input[required]').removeAttr('required');

from django-floppyforms.

carljm avatar carljm commented on May 26, 2024

Yes, the latter JS approach is what we do when we have extra empty forms. +1 to documenting both those possible approaches.

from django-floppyforms.

melinath avatar melinath commented on May 26, 2024

FTR, this also seems to break the "previous step" buttons in form wizards.

from django-floppyforms.

gregmuellegger avatar gregmuellegger commented on May 26, 2024

I think this is also a case where novalidate is the correct approach. We still need to add some documentation for this.

from django-floppyforms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.