Skip to content
Snippets Groups Projects

Issue #28: Fix mouse being pushed in /create and /edit

Merged Issue #28: Fix mouse being pushed in /create and /edit
Merged Gabriel Silva Hermida requested to merge issue/28 into development
2 files
+ 24
53
Compare changes
  • Side-by-side
  • Inline
Files
2
import * as Yup from "yup";
/** The validation through Yup is schema based, so there are schemas and it's validations. */
/** Schema to validate the question field from every form array object. */
const questionTextSchema = Yup.string()
.required("Este campo é obrigatório!")
.test("alphabets", "O caractere não é permitido", (value) => {
return /^[A-Za-z!?$%,. 1234567890àèìòùáéíóúâêîôûãõç]+$/.test(value);
});
/**Function that compares the value with a regex, to assure the input is valid */
function checkText(value) {
return /^[A-Za-z!?$%,. 1234567890àèìòùáéíóúâêîôûãõç]+$/.test(value);
}
/** Function that applies the validation of it's used schema and sets the error messages. */
export async function testQuestionTextSchema(form, value, index) {
await questionTextSchema
.validate(value)
.then((x) => {
form[index].error.errorMsg.question = "";
})
.catch((err) => {
form[index].error.errorMsg.question = err.message;
});
export async function testQuestionTextSchema(error, value) {
value
? checkText(value)
? (error.errorMsg.question = "")
: (error.errorMsg.question = "O caractere não é permitido")
: (error.errorMsg.question = "Este campo é obrigatório!");
}
/** Schema to validate the description field from every form array object. */
const descriptionTextSchema = Yup.string().test(
"alphabets",
"O caractere não é permitido",
(value) => {
if (!value) return true;
return /^[A-Za-z!?$%,. 1234567890àèìòùáéíóúâêîôûãõ\b- ]+$/.test(value);
}
);
/** Function that applies the validation of it's used schema and sets the error messages. */
export async function testDescriptionTextSchema(form, value, index) {
await descriptionTextSchema
.validate(value)
.then((x) => {
form[index].error.errorMsg.description = "";
})
.catch((err) => {
form[index].error.errorMsg.description = err.message;
});
export async function testDescriptionTextSchema(error, value) {
value && checkText(value)
? (error.errorMsg.description = "")
: (error.errorMsg.description = "O caractere não é permitido");
}
/** Schema to validate the number of options at options field from FormFieldSelect, FormFieldCheckbox and FormFieldRadio. */
const selectOptionsSchema = Yup.array()
@@ -87,23 +68,13 @@ export async function testSubformSchema(form, index) {
form[index].error.errorMsg.subformUsage = err.message;
});
}
/** Schema to validate the content of the options field from FormFieldSelect, FormFieldCheckbox and FormFieldRadio. */
const optSchema = Yup.string()
.required("Por favor, preencha esta opção")
.test("alphabets", "O caractere não é permitido", (value) => {
if (!value) return true;
return /^[A-Za-z!?$%,. àèìòùáéíóúâêîôûãõ\b- ]+$/.test(value);
});
/** Function that applies the validation of it's used schema and sets the error messages. */
export async function selectOptionTextTesting(form, value, index, idopt) {
await optSchema
.validate(value)
.then((x) => {
form[index].error.errorMsg.options[idopt] = "";
})
.catch((err) => {
form[index].error.errorMsg.options[idopt] = err.message;
});
export async function selectOptionTextTesting(error, value, idopt) {
value
? checkText(value)
? (error.errorMsg.options[idopt] = "")
: (error.errorMsg.options[idopt] = "O caractere não é permitido")
: (error.errorMsg.options[idopt] = "Por favor, preencha esta opção");
}
/** Schema to validate the quantity field of the validation from FormFieldText. */
const textValidationSchema = Yup.string()
Loading