mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 03:56:22 +00:00
feat: validación de new_array
This commit is contained in:
parent
4cdfbb7b2f
commit
2ec752ee14
4 changed files with 22 additions and 4 deletions
|
@ -20,5 +20,20 @@ export default class extends Controller {
|
|||
} else {
|
||||
this.requiredTarget.required = !Array.from(this.checkboxTargets).some(x => x.checked);
|
||||
}
|
||||
|
||||
for (const checkbox of this.checkboxTargets) {
|
||||
if (checkbox === event.target) continue;
|
||||
|
||||
checkbox.required = !event.target.checked;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Si el checkbox es considerado
|
||||
*/
|
||||
invalid(event) {
|
||||
for (const checkbox of this.checkboxTargets) {
|
||||
checkbox.required = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,12 @@
|
|||
Si la lista es obligatoria, al menos uno de los ítems tiene que
|
||||
estar activado. Logramos esto con un checkbox oculto que se marca
|
||||
como obligatorio al validar el formulario.
|
||||
- if metadata.required
|
||||
%input.form-control{ type: 'checkbox', name: name, data: { target: 'required-checkbox.required' }, required: metadata.value.empty? }
|
||||
.invalid-feedback Requerido!
|
||||
.d-flex.align-items-center.justify-content-between
|
||||
= label_tag id, post_label_t(attribute, post: post)
|
||||
%div
|
||||
= label_tag id, post_label_t(attribute, post: post), class: 'mb-0'
|
||||
- if metadata.required
|
||||
%input.form-control.d-none{ type: 'checkbox', name: name, data: { target: 'required-checkbox.required', action: 'invalid->required-checkbox#invalid' }, required: metadata.value.empty? }
|
||||
.invalid-feedback.mt-0= t('.required')
|
||||
= render 'bootstrap/btn', content: t('.edit'), action: 'modal#show'
|
||||
-# Mostramos la lista de valores actuales.
|
||||
|
||||
|
|
|
@ -764,6 +764,7 @@ en:
|
|||
edit: "Edit"
|
||||
new_array:
|
||||
edit: "Edit"
|
||||
required: "Please select at least one option."
|
||||
new_has_one:
|
||||
edit: "Edit"
|
||||
new_belongs_to:
|
||||
|
|
|
@ -772,6 +772,7 @@ es:
|
|||
edit: "Editar"
|
||||
new_array:
|
||||
edit: "Editar"
|
||||
required: "Seleccioná al menos una opción."
|
||||
new_has_one:
|
||||
edit: "Editar"
|
||||
new_belongs_to:
|
||||
|
|
Loading…
Reference in a new issue