<commit_before>define(function(require) {
  /*
    Inputs must define wizard_field="KEY"
    Inputs with the wizard_field attr will not be considered
   */
  
  return {
    'retrieve': _retrieveWizardFields,
    'fill': _fillWizardFields
  }

  // TODO: other types: radio, checkbox
  function _retrieveWizardFields(context) {
    var templateJSON = {};
    var fields = $('[wizard_field]', context);

    fields.each(function() {
      var field = $(this);

      if (field.prop('wizard_field_disabled') != true &&
            field.val() != null && field.val().length &&
            (field.attr("type") != "checkbox" || field.prop("checked"))
          ) {

        var field_name = field.attr('wizard_field');
        templateJSON[field_name] = field.val();
      }
    });
    
    return templateJSON;
  }

  function _fillWizardFields(context, templateJSON) {
    var fields = $('[wizard_field]', context);

    fields.each(function() {
      var field = $(this);
      var field_name = field.attr('wizard_field');
      if (templateJSON[field_name]) {
        switch (field.attr("type")){
        case "radio":
          var checked = (field.val() == templateJSON[field_name]);

          field.prop("checked", checked);

          if (checked) {
            field.change();
          }
          break;
        case "checkbox":
          var checked = (field.val().toUpperCase() ==
                          templateJSON[field_name].toUpperCase());

          field.prop("checked", checked);

          if (checked) {
            field.change();
          }
          break;
        default:
          field.val(templateJSON[field_name])  //TODO field.val(escapeDoubleQuotes(htmlDecode(templateJSON[field_name])));
          field.change();
        }
      }
    });
  }
});
<commit_msg>feature #3748: Add radio button support to wizard-fields<commit_after>define(function(require) {
  /*
    Inputs must define wizard_field="KEY"
    Inputs with the wizard_field attr will not be considered
   */
  
  return {
    'retrieve': _retrieveWizardFields,
    'fill': _fillWizardFields
  }

  // TODO: other types: radio, checkbox
  function _retrieveWizardFields(context) {
    var templateJSON = {};
    var fields = $('[wizard_field]', context);

    fields.each(function() {
      var field = $(this);

      if (field.prop('wizard_field_disabled') != true &&
            field.val() != null && field.val().length &&
            (field.attr("type") != "checkbox" || field.prop("checked")) &&
            (field.attr("type") != "radio" || field.prop("checked"))) {
        var field_name = field.attr('wizard_field');
        templateJSON[field_name] = field.val();
      }
    });
    
    return templateJSON;
  }

  function _fillWizardFields(context, templateJSON) {
    var fields = $('[wizard_field]', context);

    fields.each(function() {
      var field = $(this);
      var field_name = field.attr('wizard_field');
      if (templateJSON[field_name]) {
        switch (field.attr("type")){
        case "radio":
          var checked = (field.val() == templateJSON[field_name]);

          field.prop("checked", checked);

          if (checked) {
            field.change();
          }
          break;
        case "checkbox":
          var checked = (field.val().toUpperCase() ==
                          templateJSON[field_name].toUpperCase());

          field.prop("checked", checked);

          if (checked) {
            field.change();
          }
          break;
        default:
          field.val(templateJSON[field_name])  //TODO field.val(escapeDoubleQuotes(htmlDecode(templateJSON[field_name])));
          field.change();
        }
      }
    });
  }
});

{'fraction_non_alphanumeric': 0.14641407307171853, 'fraction_numerical': 0.0010825439783491205, 'mean_word_length': 2.2449517120280946, 'pattern_counts': {'":': 4, '<': 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': '5928344', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1057, 'n_words': 208}