<commit_before>/* ***********************************************
 * Validates form accroding to the definition in the HTML.
 * Is automatically loaded when included in a page.
 *
 * @author <NAME> (http://github.com/oliverroick)
 * @version 0.1
 * ***********************************************/

$(function() {
	'use strict';

	var form = $('form').not('#description-form');

	/**
	 * Displays a help text beneath invalid fields.
	 * @param  {Object} field   The invalid field
	 * @param  {String} message The message to display.
	 */
	function showHelp(field, message) {
		field.siblings('.help-block').remove();
		field.after('<span class="help-block">' + message  + '</span>');
	}

	function emailsValid(form) {
		var valid = true;

		var emailFields = $(form).find('input[type="email"]');
		for (var i = 0, len = emailFields.length; i < len; i++) {
			var email = emailFields[i].value;
			if (email.split('@')[1].indexOf('.') === -1) {
				valid = false;
				$(emailFields[i]).parents('.form-group').addClass('has-error');
				showHelp($(emailFields[i]), 'You forgot to add a top level domain to the address. Please check your input.');
			}
		}
		
		return false;
	}

	/**
	 * Validates a frorm using standard form.checkValidity(). If valid, the form is submitted.
	 * If not, invalid fields are marked and a help text is provided.
	 * @param  {Event} event The form submission event.
	 */
	function validate(event) {
		var formSumitted = event.target;
		if (formSumitted.checkValidity()) {
			// The form is valid, submit the thing
			if (emailsValid(formSumitted) && form.attr('method') && form.attr('action')) {
				$(formSumitted).off('submit');
				$(formSumitted).submit();
			}<commit_msg>Fixed email field validation<commit_after>/* ***********************************************
 * Validates form accroding to the definition in the HTML.
 * Is automatically loaded when included in a page.
 *
 * @author <NAME> (http://github.com/oliverroick)
 * @version 0.1
 * ***********************************************/

$(function() {
	'use strict';

	var form = $('form').not('#description-form');

	/**
	 * Displays a help text beneath invalid fields.
	 * @param  {Object} field   The invalid field
	 * @param  {String} message The message to display.
	 */
	function showHelp(field, message) {
		field.siblings('.help-block').remove();
		field.after('<span class="help-block">' + message  + '</span>');
	}

	function emailsValid(form) {
		var valid = true;

		var emailFields = $(form).find('input[type="email"]');
		for (var i = 0, len = emailFields.length; i < len; i++) {
			var email = emailFields[i].value;
			if (email.split('@')[1].indexOf('.') === -1) {
				valid = false;
				$(emailFields[i]).parents('.form-group').addClass('has-error');
				showHelp($(emailFields[i]), 'You forgot to add a top level domain to the address. Please check your input.');
			}
		}
		
		return valid;
	}

	/**
	 * Validates a frorm using standard form.checkValidity(). If valid, the form is submitted.
	 * If not, invalid fields are marked and a help text is provided.
	 * @param  {Event} event The form submission event.
	 */
	function validate(event) {
		var formSumitted = event.target;
		if (formSumitted.checkValidity()) {
			// The form is valid, submit the thing
			if (emailsValid(formSumitted) && form.attr('method') && form.attr('action')) {
				$(formSumitted).off('submit');
				$(formSumitted).submit();
			}
{'fraction_non_alphanumeric': 0.21034180543382996, 'fraction_numerical': 0.00292141396435875, 'mean_word_length': 3.8636363636363638, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5814679', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1014, 'n_words': 307}