/* global AutoForm */

/*
 * Template helpers for "semantic-ui" templates
 */
Template.registerHelper("attsPlusFluidClass", function attsPlusFluidClass() {
  var atts = _.clone(this.atts);

  // Add semantic-ui class
  atts = AutoForm.Utility.addClass(atts, "fluid");

  return atts;
});

Template.registerHelper("attsPlusButtonClass", function attsPlusButtonClass() {
  var atts = _.clone(this.atts);

  // Add semantic-ui class
  atts = AutoForm.Utility.addClass(atts, "ui blue button");

  return atts;
});

Template.autoForm.helpers({
  atts: function autoFormTplAtts() {
    var context = _.clone(this);

    if (context.validation !== "browser" && !context.novalidate) {
      context.novalidate = "novalidate";
    }

    context = AutoForm.Utility.addClass(context, "ui form");

    return _.omit(context,
      "schema",
      "collection",
      "validation",
      "doc",
      "resetOnSuccess",
      "type",
      "template",
      "autosave",
      "meteormethod",
      "filter",
      "autoConvert",
      "removeEmptyStrings",
      "trimStrings",
      "_resolvedSchema"
    );
  }
});

@@ -577,151 +577,193 @@
     
-var context = _.clone(this);%0A%0A    if (context.validation !== %22browser%22 && !context.novalidate) %7B%0A      context.novalidate = %22novalidate%22;%0A    %7D
+// After removing all of the props we know about, everything else should%0A    // become a form attribute unless it's an array or object.%0A    var val, htmlAttributes = %7B%7D, context = this;
 %0A%0A  
@@ -830,30 +830,27 @@
     
-return _.omit(context,
+var removeProps = %5B
 %0A   
@@ -985,24 +985,49 @@
 %22autosave%22,%0A
+      %22autosaveOnKeyup%22,%0A
       %22meteo
@@ -1124,39 +1124,956 @@
 ngs%22
-,%0A      %22_resolvedSchema%22%0A    )
+%0A    %5D;%0A%0A    // Filter out any attributes that have a component prefix%0A    function hasComponentPrefix(prop) %7B%0A      return _.any(AutoForm.Utility.componentTypeList, function (componentType) %7B%0A        return prop.indexOf(componentType + '-') === 0;%0A      %7D);%0A    %7D%0A%0A    // Filter out arrays and objects, which are obviously not meant to be%0A    // HTML attributes.%0A    for (var prop in context) %7B%0A      if (context.hasOwnProperty(prop) &&%0A          !_.contains(removeProps, prop) &&%0A          !hasComponentPrefix(prop)) %7B%0A        val = context%5Bprop%5D;%0A        if (!_.isArray(val) && !_.isObject(val)) %7B%0A          htmlAttributes%5Bprop%5D = val;%0A        %7D%0A      %7D%0A    %7D%0A%0A    // By default, we add the %60novalidate=%22novalidate%22%60 attribute to our form,%0A    // unless the user passes %60validation=%22browser%22%60.%0A    if (this.validation !== %22browser%22 && !htmlAttributes.novalidate) %7B%0A      htmlAttributes.novalidate = %22novalidate%22;%0A    %7D%0A%0A    return htmlAttributes
 ;%0A  

Patch semantic-ui.js with latest changes from autoForm.js. Fixes issue #23.