<commit_before>const $ = require('jquery');

const Keys = require('keys/dist/client');

$(() => {
  $('body').on('click', '[type="submit"]', ev => {
    const $btn = $(ev.target);
    const $form = $btn.closest('form');

    Keys.clearFieldErrors($form);

    $form.find('[required]').each((i, el) => {
      const $el = $(el);

      if (!$el.val()) {
        ev.preventDefault();
        Keys.flagFieldError($el, 'Preenchimento obrigatório.');
      }
    });

    $form.find('[type="email"]').each((i, el) => {
      const $el = $(el);

      const re = /^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-\.]+\.[a-zA-Z0-9_\-]+$/;

      if (!re.test($el.val())) {
        ev.preventDefault();
        Keys.flagFieldError($el, 'E-mail inválido.');
      }
    });
  });
});<commit_msg>[Admin] Allow blank non-required e-mail fields.<commit_after>const $ = require('jquery');

const Keys = require('keys/dist/client');

$(() => {
  $('body').on('click', '[type="submit"]', ev => {
    const $btn = $(ev.target);
    const $form = $btn.closest('form');

    Keys.clearFieldErrors($form);

    $form.find('[required]').each((i, el) => {
      const $el = $(el);

      if (!$el.val()) {
        ev.preventDefault();
        Keys.flagFieldError($el, 'Preenchimento obrigatório.');
      }
    });

    $form.find('[type="email"]').each((i, el) => {
      const $el = $(el);
      const val = $el.val();

      const re = /^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-\.]+\.[a-zA-Z0-9_\-]+$/;

      if (val && !re.test(val)) {
        ev.preventDefault();
        Keys.flagFieldError($el, 'E-mail inválido.');
      }
    });
  });
});
{'fraction_non_alphanumeric': 0.2690387016229713, 'fraction_numerical': 0.00749063670411985, 'mean_word_length': 2.462203023758099, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5499660', 'n_tokens_mistral': 617, 'n_tokens_neox': 595, 'n_words': 89}