add validation for empty motivation field with javascript
This commit is contained in:
parent
a694d65911
commit
890e00f915
2 changed files with 33 additions and 2 deletions
|
@ -58,6 +58,37 @@ export class BatchOperationController extends ApplicationController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSubmitInstruction(event: { srcElement: HTMLInputElement }) {
|
||||||
|
const field_refuse = document.querySelector<HTMLInputElement>(
|
||||||
|
'.js_batch_operation_motivation_refuse'
|
||||||
|
);
|
||||||
|
|
||||||
|
const field_without_continuation = document.querySelector<HTMLInputElement>(
|
||||||
|
'.js_batch_operation_motivation_without-continuation'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (field_refuse != null) {
|
||||||
|
if (event.srcElement.value == 'refuser' && field_refuse.value == '') {
|
||||||
|
field_refuse.setCustomValidity('La motivation doit être remplie');
|
||||||
|
} else {
|
||||||
|
field_refuse.setCustomValidity('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field_without_continuation != null) {
|
||||||
|
if (
|
||||||
|
event.srcElement.value == 'classer_sans_suite' &&
|
||||||
|
field_without_continuation.value == ''
|
||||||
|
) {
|
||||||
|
field_without_continuation.setCustomValidity(
|
||||||
|
'La motivation doit être remplie'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
field_without_continuation.setCustomValidity('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onDeleteSelection(event: { preventDefault: () => void }) {
|
onDeleteSelection(event: { preventDefault: () => void }) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
emptyCheckboxes();
|
emptyCheckboxes();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
%div{ class: "motivation #{instruction_operation}" }
|
%div{ class: "motivation #{instruction_operation}" }
|
||||||
= form.text_area :motivation, class: 'fr-input'
|
= form.text_area :motivation, class: "fr-input js_batch_operation_motivation_#{instruction_operation}"
|
||||||
.optional-justificatif{ id: "justificatif_motivation_suggest_#{instruction_operation}" }
|
.optional-justificatif{ id: "justificatif_motivation_suggest_#{instruction_operation}" }
|
||||||
%button.fr-btn.fr-btn--sm.fr-btn--tertiary-no-outline.fr-btn--icon-left.fr-icon-attachment-line.fr-ml-0{ type: 'button', onclick: "DS.showImportJustificatif('#{instruction_operation}');" } Ajouter un justificatif (optionnel)
|
%button.fr-btn.fr-btn--sm.fr-btn--tertiary-no-outline.fr-btn--icon-left.fr-icon-attachment-line.fr-ml-0{ type: 'button', onclick: "DS.showImportJustificatif('#{instruction_operation}');" } Ajouter un justificatif (optionnel)
|
||||||
.hidden{ id: "justificatif_motivation_import_#{instruction_operation}" }
|
.hidden{ id: "justificatif_motivation_import_#{instruction_operation}" }
|
||||||
|
@ -10,4 +10,4 @@
|
||||||
|
|
||||||
= button_tag "Annuler", type: :reset, class: 'fr-btn fr-btn--sm fr-btn--secondary', onclick: 'DS.motivationCancelBatch();'
|
= button_tag "Annuler", type: :reset, class: 'fr-btn fr-btn--sm fr-btn--secondary', onclick: 'DS.motivationCancelBatch();'
|
||||||
|
|
||||||
= form.button "Valider la décision", class: ['fr-btn fr-btn--sm fr-mt-2w'], disabled: true, name: "#{form.object_name}[operation]", value: opt[:operation], data: { operation: opt[:operation] }
|
= form.button "Valider la décision", class: ['fr-btn fr-btn--sm fr-mt-2w'], disabled: true, name: "#{form.object_name}[operation]", value: opt[:operation], data: { operation: opt[:operation], action: "batch-operation#onSubmitInstruction" }
|
||||||
|
|
Loading…
Reference in a new issue