<commit_before>import Ember from 'ember';
import layout from '../templates/components/form-for';

const {
  get,
  isPresent,
  set,
  Component
} = Ember;

const FormForComponent = Component.extend({
  layout,

  tagName: 'form',

  attributeBindings: ['tabindex'],
  tabindex: '-1',

  submit: (object) => object.save(),
  reset:  (object) => object.rollback(),

  update(object, propertyName, value) {
    set(object, propertyName, value);
  },

  actions: {
    submit(object) {
      get(this, 'submit')(object);

      let errors = get(object, 'errors');
      if (errors) {
        for (let propertyName in errors) {
          if (isPresent(get(errors, propertyName))) {
            this.$().focus();
            break;
          }
        }
      }
    }
  }<commit_msg>Only add tabindex to form when form has errors<commit_after>import Ember from 'ember';
import layout from '../templates/components/form-for';

const {
  get,
  isPresent,
  set,
  run: { schedule },
  Component
} = Ember;

const FormForComponent = Component.extend({
  layout,

  tagName: 'form',

  attributeBindings: ['tabindex'],

  submit: (object) => object.save(),
  reset:  (object) => object.rollback(),

  update(object, propertyName, value) {
    set(object, propertyName, value);
  },

  actions: {
    submit(object) {
      get(this, 'submit')(object);
      set(this, 'tabindex', undefined);

      let errors = get(object, 'errors');
      if (errors) {
        for (let propertyName in errors) {
          if (isPresent(get(errors, propertyName))) {
            set(this, 'tabindex', -1);
            schedule('afterRender', () => this.$().focus());
            break;
          }
        }
      }
    }
  }
{'fraction_non_alphanumeric': 0.154524089306698, 'fraction_numerical': 0.0011750881316098707, 'mean_word_length': 2.577731092436975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '7458807', 'n_tokens_mistral': 537, 'n_tokens_neox': 523, 'n_words': 127}