lib/helpers/get-form-view-model.js
function getFormFields(form) {
  // Grab all fields that are enabled, and return them as an array.
  // If enabled, remove that property and apply the field name.
  var fields = Object.keys(form.fields).reduce(function (result, fieldKey) {
    var field = _.clone(form.fields[fieldKey]);

    if (!field.enabled) {
      return result;
    }

    // Append the field to field order in case it's not present.
    if (form.fieldOrder.indexOf(fieldKey) === -1) {
      form.fieldOrder.push(fieldKey);
    }

    field.name = fieldKey;
    delete field.enabled;

    result.push(field);

    return result;
  }, []);

  // Sort fields by the defined fieldOrder.
  // Fields that are not in fieldOrder will be placed at the end of the array.
  fields.sort(function (a, b) {
    var indexA = form.fieldOrder.indexOf(a.name);
    var indexB = form.fieldOrder.indexOf(b.name);

    if (indexA === -1) {
      return 0;
    }

    if (indexB === -1) {
      return -1;
    }

    if (indexA > indexB) {
      return 1;
    }

    if (indexA < indexB) {
      return -1;
    }

    return 0;
  });

  return fields;
}
function getFormFields(form) {
  // Grab all fields that are enabled, and return them as an array.
  // If enabled, remove that property and apply the field name.
  var fields = Object.keys(form.fields).reduce(function (result, fieldKey) {
    var field = _.clone(form.fields[fieldKey]);

    if (!field.enabled) {
      return result;
    }

    // Append the field to field order in case it's not present.
    if (form.fieldOrder.indexOf(fieldKey) === -1) {
      form.fieldOrder.push(fieldKey);
    }

    field.name = fieldKey;
    delete field.enabled;

    result.push(field);

    return result;
  }, []);

  // Sort fields by the defined fieldOrder.
  // Fields that are not in fieldOrder will be placed at the end of the array.
  fields.sort(function (a, b) {
    var indexA = form.fieldOrder.indexOf(a.name);
    var indexB = form.fieldOrder.indexOf(b.name);

    if (indexA === -1) {
      return 0;
    }

    if (indexB === -1) {
      return -1;
    }

    if (indexA > indexB) {
      return 1;
    }

    if (indexA < indexB) {
      return -1;
    }

    return 0;
  });

  return fields;
}
function getFormFields ( form ) { // Grab all fields that are enabled, and return them as an array. // If enabled, remove that property and apply the field name. var fields = Object . keys ( form . fields ) . reduce ( function ( result , fieldKey ) { var field = _ . clone ( form . fields [ fieldKey ] ) ; if ( ! field . enabled ) { return result ; } // Append the field to field order in case it's not present. if ( form . fieldOrder . indexOf ( fieldKey ) === - 1 ) { form . fieldOrder . push ( fieldKey ) ; } field . name = fieldKey ; delete field . enabled ; result . push ( field ) ; return result ; } , [ ] ) ; // Sort fields by the defined fieldOrder. // Fields that are not in fieldOrder will be placed at the end of the array. fields . sort ( function ( a , b ) { var indexA = form . fieldOrder . indexOf ( a . name ) ; var indexB = form . fieldOrder . indexOf ( b . name ) ; if ( indexA === - 1 ) { return 0 ; } if ( indexB === - 1 ) { return - 1 ; } if ( indexA > indexB ) { return 1 ; } if ( indexA < indexB ) { return - 1 ; } return 0 ; } ) ; return fields ; }
Returns list of all enabled fields, as defined by `form.fields`,
and ordered by `form.fieldOrder`.

@method

@param {Object} form - The form from the Stormpath configuration.
Returns list of all enabled fields as defined by form . fields and ordered by form . fieldOrder .