Skip to content

Commit

Permalink
Workaround for ministryofjustice/moj-frontend#343 and ignore js files…
Browse files Browse the repository at this point in the history
… copied to make MoJ frontend library work
  • Loading branch information
Taoufik Mohdit authored and Taoufik Mohdit committed Apr 11, 2022
1 parent f150b00 commit f418fe0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ coverage/*
# custom definition files
/src/main/types/
jest.*config.js
/src/main/assets/js/jquery.js
/src/main/assets/js/mojAll.js
24 changes: 24 additions & 0 deletions src/main/assets/js/remove-error-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This is a workaround for https://github.com/ministryofjustice/moj-frontend/issues/343
* For the workaround to work, add buttons using MoJ add-another library have to have their HTML ids added to
* addButtonsIds list.
* The logic below may have to be adjusted if the duplicated/added item has different error classes.
* Once the issue above addressed, MoJ library can be upgraded and this workaround can be discarded.
*/
const addButtonIds = [
'add-another-court-order',
];

addButtonIds.forEach(addButtonId => document.getElementById(addButtonId).addEventListener('click', () => {
[...document.getElementsByClassName('govuk-error-summary')]
.forEach(errorSummary => errorSummary.classList.add('hide'));
[...document.getElementsByClassName('govuk-error-message')]
.forEach(errorMessage => errorMessage.classList.add('hide'));
[...document.getElementsByClassName('govuk-input--error')]
.forEach(inputError => inputError.classList.remove('govuk-input--error'));
[...document.getElementsByClassName('govuk-form-group--error')]
.forEach(errorMessage => {
errorMessage.classList.add('govuk-form-group');
errorMessage.classList.remove('govuk-form-group--error');
});
}));
5 changes: 5 additions & 0 deletions src/main/assets/scss/main.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
@import '~govuk-frontend';

.moj-add-another {
// sass-lint:disable class-name-format
&__remove-button {
display: none;
}
}

.hide {
display: none;
}
3 changes: 2 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import './assets/scss/main.scss';
import './assets/js/postcode-lookup.js';
import './assets/js/append-row.js';
import { initAll } from 'govuk-frontend';
import './assets/js/jquery';
import './assets/js/mojAll';
import './assets/js/remove-error-content';
import { initAll } from 'govuk-frontend';

initAll();
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
{{ govukButton({
text: t('Add another court order'),
classes: 'govuk-button--secondary moj-add-another__add-button govuk-!-margin-bottom-1',
type: 'button'
type: 'button',
attributes: {
'id': 'add-another-court-order'
}
}) }}
</div>
</div>
Expand Down

0 comments on commit f418fe0

Please sign in to comment.