<commit_before>var conditionalHTML = require('./conditional-input-card.html');
var InputCard = require('./card-input.js');



/**
 * This Card extends the functionality of InputCard. It gives the ability of disabling the InputCard.
 * This is useful in situations where you don't want the Card to be required.
 *
 * @param {jquery} appendTo The div to append this Card to.
 * @param {Object} options The object that describes the Card functionality. See the parent object InputCard for details.
 * @param {boolean} enabled The default state of the checkbox.
 */
var ConditionalInputCard = function(appendTo, options) {
  InputCard.call(this, appendTo, options);

  // Private variables
  var self = this;
  var innerBase = $(conditionalHTML);
  var checkbox = innerBase.find('[data-id="checkbox"]');
  var cbLabel = innerBase.find('[data-id="checkbox-label"]');

  //***** Private Methods *****//

  this.init_ = function(appendTo, options) {
    this.append(innerBase);

    checkbox.on('change', setCardState);

    componentHandler.upgradeAllRegistered();

    if (options.enabled !== undefined) {
      if (options.enabled) {
        checkbox.attr('checked');
      }
    }
    if (options.checkboxText !== undefined) {
      cbLabel.text(options.checkboxText);
    }
  };

  var setCardState = function(e) {
    // NOTE MDL doesn't change the class until after this event is fired. That revereses our logic here.
    if (!self.isEnabled()) {
      enableCard();
    }
    else {
      disableCard();
    }
  };

  var disableCard = function() {
    self.disableInput();
  };

  var enableCard = function() {
    self.enableInput();
  };

  var oldGetValue = this.getValue;

  //***** Public Functions *****//

  /**
   * Checks whether this Card is enabled.
   *
   * @returns {boolean} True if the Card is enabled. False if it isn't.
   */
  this.isEnabled = function() {
    return innerBase.hasClass('is-checked');
  };

  this.check = function() {
    innerBase[0].MaterialCheckbox.check();
  };

  this.uncheck = function() {
    innerBase[0].MaterialCheckbox.uncheck();
  };

  this.getValue = function() {
    if (self.isEnabled()) {
      return oldGetValue();
    }
    return;
  }<commit_msg>Fixed an issue with toggling states for ConditionalInputs.<commit_after>var conditionalHTML = require('./conditional-input-card.html');
var InputCard = require('./card-input.js');



/**
 * This Card extends the functionality of InputCard. It gives the ability of disabling the InputCard.
 * This is useful in situations where you don't want the Card to be required.
 *
 * @param {jquery} appendTo The div to append this Card to.
 * @param {Object} options The object that describes the Card functionality. See the parent object InputCard for details.
 * @param {boolean} enabled The default state of the checkbox.
 */
var ConditionalInputCard = function(appendTo, options) {
  InputCard.call(this, appendTo, options);

  // Private variables
  var self = this;
  var innerBase = $(conditionalHTML);
  var checkbox = innerBase.find('[data-id="checkbox"]');
  var cbLabel = innerBase.find('[data-id="checkbox-label"]');

  //***** Private Methods *****//

  this.init_ = function(appendTo, options) {
    this.append(innerBase);

    checkbox.on('change', setCardState);

    componentHandler.upgradeAllRegistered();

    if (options.enabled !== undefined) {
      if (options.enabled) {
        checkbox.attr('checked');
      }
    }
    if (options.checkboxText !== undefined) {
      cbLabel.text(options.checkboxText);
    }
  };

  var setCardState = function(e) {
    // NOTE MDL doesn't change the class until after this event is fired. That revereses our logic here.
    if (!self.isEnabled()) {
      enableCard();
    }
    else {
      disableCard();
    }
  };

  var disableCard = function() {
    self.disableInput();
  };

  var enableCard = function() {
    self.enableInput();
  };

  var oldGetValue = this.getValue;

  //***** Public Functions *****//

  /**
   * Checks whether this Card is enabled.
   *
   * @returns {boolean} True if the Card is enabled. False if it isn't.
   */
  this.isEnabled = function() {
    return innerBase.hasClass('is-checked');
  };

  this.check = function() {
    innerBase[0].MaterialCheckbox.check();
    enableCard();
  };

  this.uncheck = function() {
    innerBase[0].MaterialCheckbox.uncheck();
    disableCard();
  };

  this.getValue = function() {
    if (self.isEnabled()) {
      return oldGetValue();
    }
    return;
  }
{'fraction_non_alphanumeric': 0.1376779359430605, 'fraction_numerical': 0.0008896797153024911, 'mean_word_length': 3.1677479147358665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '924173', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1283, 'n_words': 377}