Giter Club home page Giter Club logo

Comments (9)

marxsk avatar marxsk commented on August 17, 2024 4

@poteto The validation that is proposed works nice but it expects you to define changeset outside of templates. When (changeset data validation) is used I'm not able to find a way how to do it and I have to modify your module.

It is enough to extend function changeset([model, validationMap]) with changset.validate(). This should be configurable, so adding a new attribute (e.g. initValidation with false as a default) looks sensible. If I will prepare PR, are you willing to merge it?

from ember-changeset-validations.

poteto avatar poteto commented on August 17, 2024

Could you call validate on the init of whatever it is that's being instantiated, like in your snippet above?

from ember-changeset-validations.

utilityboy avatar utilityboy commented on August 17, 2024

@poteto For sure, but it does limit building validated changesets in a template. Should this be a default behaviour in your mind? Perhaps an option that can be passed to the constructor?

from ember-changeset-validations.

utilityboy avatar utilityboy commented on August 17, 2024

@marxsk That's what I ultimately ended up doing and just setting a controller or component property for the template to bind to the pre-validated changeset object.

from ember-changeset-validations.

MrChocolatine avatar MrChocolatine commented on August 17, 2024

@poteto could we bump this issue ? This is badly needed.
I have the same issue and using validate() right after the Changeset has been initialised is not the proper solution I think.
For instance, by doing that it forces all the error messages to show up on the first render of a form.

from ember-changeset-validations.

kpfefferle avatar kpfefferle commented on August 17, 2024

@MrChocolatine I often use the suggested pattern with much success. I call validate() right after initializing the Changeset, but then I hide validation errors in the form until other events occur such as an individual input blur (show errors for that field) or the user tries to submit the form (show errors for all fields). I really like the flexibility and control that this approach gives me.

from ember-changeset-validations.

MrChocolatine avatar MrChocolatine commented on August 17, 2024

To me it sounds more like an incorrect implementation. We should not to have to do this manually and a first validation should occur internally, when the Changeset is created. Or at least via an option as already suggested.

from ember-changeset-validations.

snewcomer avatar snewcomer commented on August 17, 2024

@MrChocolatine Appreciate the input! I certainly think an optional initValidation boolean approach is worthwhile and will help give users visibility into the initial state of the changeset without hooking into the JS side of things. I generally wait until user input to perform any of this logic (submit/blur) but I can see that limited use cases may require this API. I created an issue in ember-changeset to track and implement.

poteto/ember-changeset#451

from ember-changeset-validations.

MrChocolatine avatar MrChocolatine commented on August 17, 2024

Thank you @snewcomer 👍 .

from ember-changeset-validations.

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.