ministryofjustice/Claim-for-Crown-Court-Defence

View on GitHub
app/webpack/javascripts/modules/external_users/claims/DefendantsCtrl.js

Summary

Maintainability
A
0 mins
Test Coverage
moj.Modules.DefendantsCtrl = {
  init: function () {
    this.addCocoonHooks()
  },

  addCocoonHooks: function () {
    let counter = 0

    $('#defendants').on('cocoon:before-insert', function (e, insertedItem) {
      insertedItem.find(':input').each(function () {
        const inputId = $(this).attr('id')
        const newId = (inputId || '').concat('-', counter++)

        $(this).attr('id', newId)
        $(this).siblings('label').attr('for', newId)
      })
    })
  }
}