jeudi 22 octobre 2015

Incrementing a tabindex property in Ember template

I'm trying to display forms with a mixin that automatically increments the tabindex property in forms.

import Ember from 'ember';

const {
  computed,
  Mixin
} = Ember;

export default Mixin.create({

  baseTabIndex: 0,

  tabindex: computed('baseTabIndex', function() {
    this.incrementProperty('baseTabIndex');
    return this.get('baseTabIndex');
  }).volatile()

});

In templates, I'd use it like so:

{{input value=foo tabindex=tabindex}}
{{input value=bar tabindex=tabindex}}

I thought that volatile would mean that the value wasn't cached so I'd get 1, 2 as the values. But it's always 1. How can I do this with a computed property?




Aucun commentaire:

Enregistrer un commentaire