<commit_before>import { VALIDATION_MESSAGE_PASSWORDS_MATCH } from '../constants';
import { isObject, isString } from './isType';

const getHelpBlock = (id) => {
  if (isString(id)) {
    return `<span id="${id}" class="help-block" style="display:none;">
            ${VALIDATION_MESSAGE_PASSWORDS_MATCH}</span>`;
  }
};

const isValid = (pwd, confirmation) => {
  return pwd === confirmation;
};

const valid = (el, block) => {
  $(el).attr('aria-invalid', false);
  $(el).parent().removeClass('has-error');
  $(`#${block}`).hide();
};
const invalid = (el, block) => {
  $(el).attr('aria-invalid', true);
  $(el).parent().addClass('has-error');
  $(`#${block}`).show();
};

export default (options) => {
  if (isObject(options) && isString(options.selector)) {
    const id = `${options.selector}_password_matcher`;

    const pwd = $(`${options.selector} #user_password`);
    const cnf = $(`"${options.selector} #user_password_confirmation`);
    const sbmt = $(`${options.selector} input[type="submit"]`);

    if (isObject(pwd) && isObject(cnf) && isObject(sbmt)){
      if (isValid($(pwd).val(), $(cnf).val())) {
        $(cnf).after(getHelpBlock(id));
        $(cnf).attr('aria-describedby', id);

        $(sbmt).click((e) => {
          if (cnf !== pwd) {
            e.preventDefault();
            invalid(cnf, id);
          } else {
            valid(cnf, id);
          }
        });
      }
    }
  }
};<commit_msg>updated jquery selectors for matching password DMPRoadmap/roadmap#558<commit_after>import { VALIDATION_MESSAGE_PASSWORDS_MATCH } from '../constants';
import { isObject, isString } from './isType';

const getHelpBlock = (id) => {
  if (isString(id)) {
    return `<span id="${id}" class="help-block" style="display:none;">
            ${VALIDATION_MESSAGE_PASSWORDS_MATCH}</span>`;
  }
};

const isValid = (pwd, confirmation) => {
  return pwd === confirmation;
};

const valid = (el, block) => {
  $(el).attr('aria-invalid', false);
  $(el).parent().removeClass('has-error');
  $(`#${block}`).hide();
};
const invalid = (el, block) => {
  $(el).attr('aria-invalid', true);
  $(el).parent().addClass('has-error');
  $(`#${block}`).show();
};

export default (options) => {
  if (isObject(options) && isString(options.selector)) {
    const id = `${options.selector}_password_matcher`;

    const pwd = $(options.selector).find('#user_password');
    const cnf = $(options.selector).find('#user_password_confirmation');
    const sbmt = $(options.selector).find('input[type="submit"]');

    if (isObject(pwd) && isObject(cnf) && isObject(sbmt)){
      if (isValid($(pwd).val(), $(cnf).val())) {
        $(cnf).after(getHelpBlock(id));
        $(cnf).attr('aria-describedby', id);

        $(sbmt).click((e) => {
          if (cnf !== pwd) {
            e.preventDefault();
            invalid(cnf, id);
          } else {
            valid(cnf, id);
          }
        });
      }
    }
  }
};
{'fraction_non_alphanumeric': 0.21800136892539357, 'fraction_numerical': 0.001026694045174538, 'mean_word_length': 3.260932944606414, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '6813229', 'n_tokens_mistral': 983, 'n_tokens_neox': 985, 'n_words': 171}