Code Monkey home page Code Monkey logo

Comments (9)

horprogs avatar horprogs commented on August 30, 2024 1

I added revalidate() and revalidateField() methods. Could you check please, does it solve your issue?

from just-validate.

horprogs avatar horprogs commented on August 30, 2024

Hi! I guess for the first option you could use existing validate() method, like:

const fv = new JustValidate("form", {
    ...
  });
fv.validate()

For validating field I'll look into that

from just-validate.

shivam091 avatar shivam091 commented on August 30, 2024

I'll check it. Thanks.

from just-validate.

shivam091 avatar shivam091 commented on August 30, 2024

Hi,

I was going throgh implementing revalidateField() on browser console, I found that, in both cases (valid image and invalid image), method is returning undefined however field is getting revalidated.

How can I get to know that field was valid or not. I think, it should return true or false depending on validation sucess and failure.

First execution is for valid image and second one is for invalid image:

avatarForm.revalidateField("#real-file")
-> undefined
avatarForm.revalidateField("#real-file")
-> undefined

For reference, I have below added JS

NOTE: $ is function shorthand for document.querySelector

if (typeof($(".avatar-form")) != "undefined" && $(".avatar-form") != null) {
    avatarForm = new JustValidate(".avatar-form", {
      errorFieldCssClass: "is-invalid",
      errorLabelCssClass: "invalid-feedback",
      successFieldCssClass: "is-valid",
      successLabelCssClass: "valid-feedback",
      focusInvalidField: true,
      lockForm: false,
      tooltip: {
        position: "top"
      },
    }).onSuccess((event) => {
      event.preventDefault();
      Turbo.navigator.submitForm(event.target);
    }).onFail((fields) => {
      setErrorElementStyles();
    });

    if (typeof($("#real-file")) != "undefined" && $("#real-file") != null) {
      avatarForm.addField("#real-file", [
        {
          rule: "minFilesCount",
          value: 1,
          errorMessage: I18n.t("javascripts.validation_error_messages.avatars.image.required")
        },
        {
          rule: "maxFilesCount",
          value: 1,
          errorMessage: I18n.t("javascripts.validation_error_messages.avatars.image.required")
        },
        {
          rule: "files",
          value: {
            files: {
              extensions: ["jpe", "jpg", "jpeg", "png"],
              minSize: 1 * 10 * 1024,
              maxSize: 2 * 1024 * 1024,
              types: ["image/jpeg", "image/jpg", "image/png"],
            },
          },
          errorMessage: I18n.t("javascripts.validation_error_messages.avatars.image.file")
        },
      ]);
    }
  }

from just-validate.

shivam091 avatar shivam091 commented on August 30, 2024

Hi.
In addition to above I tried using validate() but it didn't validated form

avatarForm.validate();

but revalidate() is able to validate the form but it also returned me undefined (I think, it should also return true or false).

avatarForm.validate();
-> Promise {<fulfilled>: true}
avatarForm.revalidate();
-> undefined

from just-validate.

shivam091 avatar shivam091 commented on August 30, 2024

If it is possible then can these method return true/false. so that it can be easier to get to know that the form or field is validated successfully or not and this will help me to show image preview of file only if these methods will return true

Thanks.

from just-validate.

horprogs avatar horprogs commented on August 30, 2024

Hey, now, .revalidate() and .revalidateField() methods return a promise (because validation is actually is an async function) with a boolean value: valid or not:

validation.revalidateField('#name').then(isValid => {
   
})

from just-validate.

shivam091 avatar shivam091 commented on August 30, 2024

Okay thank you.

from just-validate.

shivam091 avatar shivam091 commented on August 30, 2024

Okay thank you.

I will look into this

from just-validate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.