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

no hardwired submit button #17

Open
jamesmc opened this issue Sep 18, 2024 · 0 comments
Open

no hardwired submit button #17

jamesmc opened this issue Sep 18, 2024 · 0 comments

Comments

@jamesmc
Copy link

jamesmc commented Sep 18, 2024

Is your feature request related to a problem? Please describe.
The submit button is hardwired into the form template. More flexibility with how to submit forms would be good.

Describe the solution you'd like
It should be possible to have different ways to trigger the submit event so that the form can do different things on submit. In particular, it would be nice to be able to navigate away from the form to a submission successful page or a second form page, etc after submit.

Describe alternatives you've considered
I have come up with my own workaround. I have modified templates/djangocms_form_builder/ajax_form.html to add a click event listener to any anchor elements on the form that then triggers the forms submit event. This means that any djangocms_link plugin added to the form will trigger submit. I have also removed the hardwired submit input from templates/djangocms_form_builder/bootstrap5/form.html

Here is a snippet of my modified code for ajax_form.html:

`{% addtoblock 'js' %}<script>
(function () {
function initForms() {
for (let form of document.getElementsByClassName('djangocms-form-builder-ajax-form')) {

            djangocms_form_builder_form(form);
            
            //custom code to allow links inserted into the form to trigger form submission
            for(let link of form.getElementsByTagName('a')) {
                link.addEventListener('click', function (event) {
                    form.submit();
                });

            }                
        }
    }
    window.addEventListener('DOMContentLoaded', initForms);
    {% if request.toolbar and request.toolbar.edit_mode_active %}
        CMS.$(window).on('cms-content-refresh', initForms);
    {% endif %}
})();

</script>{% endaddtoblock %}`

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