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

Checkbox validation: The form is being sent although required checkbox is not checked #216

Closed
pshemek opened this issue Dec 4, 2017 · 1 comment

Comments

@pshemek
Copy link

pshemek commented Dec 4, 2017

The form definition:

form:
  name: registration-form
  template: form-messages
  fields:
    - name: first_name
      label: First name
      type: text
      validate:
        required: true
    - name: accept_rules
      label: Accept rules
      type: checkbox
      validate:
        required: true
  buttons:
    - type: submit
      value: Send
  process:
    - save:
        fileprefix: registration-
        dateformat: Ymd-His-u
        extension: txt
        body: "{% include 'forms/data.txt.twig' %}"
    - message: Thank you!

This is AJAX form. I need to mention that I've set the novalidate attribute on the <form> tag because I don't want a browser validation. I utilize own Twig template extending the default one.

{% extends "forms/default/form.html.twig" %}

{% block form_classes %}
class="{{ form_outer_classes }} {{ form.classes }}" novalidate
{% endblock %}

{% block inner_markup_buttons_end %}
	</div>
	<div id="form-result"></div>
	<script>
		$(document).ready(function(){
			var form = $('#registration-form');
			form.submit(function(e) {
				// prevent form submission
				e.preventDefault();

				// submit the form via Ajax
				$.ajax({
					url: form.attr('action'),
					type: form.attr('method'),
					dataType: 'html',
					data: form.serialize(),
					success: function(result) {
						// Inject the result in the HTML
						$('#form-result').html(result);
					}
				});
			});
		});
	</script>
{% endblock %}

Forms plugin returns validation message related to the text field but talks nothing about the checkbox which is expected to be validated as well:

validation

On the other hand, when I fill just the first name, the form is sent.

@rhukster rhukster added the bug label Dec 4, 2017
@rhukster rhukster self-assigned this Dec 4, 2017
@rhukster
Copy link
Member

rhukster commented Dec 5, 2017

Should be fixed in develop branch of Grav

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants