<commit_before>'use strict';
var _ = require('lodash'),
  dom = require('../services/dom');

module.exports = function (result, args) {
  var el = result.el,
    bindings = result.bindings,
    rivets = result.rivets,
    tpl = `
      <span class="soft-maxlength">{ max | charsRemaining data }</span>
    `,
    span = dom.create(tpl);

  bindings.max = args.value;
  rivets.formatters.charsRemaining = function (max, data) {
    var length = parseInt(data.length),
      remaining = max - length,
      input = dom.find(el, 'input');

    if (remaining > 0) {
      span.classList.remove('too-long');
      input.setCustomValidity('');
      return remaining + ' characters remaining';
    } else if (remaining === 0) {
      span.classList.remove('too-long');
      input.setCustomValidity('');
      return -remaining + ' characters over limit!';
    } else {
      span.classList.add('too-long');
      input.setCustomValidity(input.getAttribute('name') + ' is too long!');
      return -remaining + ' characters over limit!';
    }
  };

  dom.insertAfter(dom.find(el, '.label-inner'), span);
  return result;
};<commit_msg>use label for validation message<commit_after>'use strict';
var _ = require('lodash'),
  dom = require('../services/dom');

module.exports = function (result, args) {
  var el = result.el,
    bindings = result.bindings,
    rivets = result.rivets,
    tpl = `
      <span class="soft-maxlength">{ max | charsRemaining data }</span>
    `,
    span = dom.create(tpl);

  bindings.max = args.value;
  rivets.formatters.charsRemaining = function (max, data) {
    var length = parseInt(data.length),
      remaining = max - length,
      input = dom.find(el, 'input'),
      label = dom.find(el, '.label-inner').innerText;

    if (remaining > 0) {
      span.classList.remove('too-long');
      input.setCustomValidity('');
      return remaining + ' characters remaining';
    } else if (remaining === 0) {
      span.classList.remove('too-long');
      input.setCustomValidity('');
      return -remaining + ' characters over limit!';
    } else {
      span.classList.add('too-long');
      input.setCustomValidity(label + ' is too long!');
      return -remaining + ' characters over limit!';
    }
  };

  dom.insertAfter(dom.find(el, '.label-inner'), span);
  return result;
};
{'fraction_non_alphanumeric': 0.16003460207612458, 'fraction_numerical': 0.0017301038062283738, 'mean_word_length': 2.9879310344827585, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4092011', 'n_tokens_mistral': 732, 'n_tokens_neox': 728, 'n_words': 161}