Coder Social home page Coder Social logo

Comments (6)

philfreo avatar philfreo commented on June 12, 2024

From the README:

There are 2 levels of validation: schema validators and the regular built-in Backbone model validation. Backbone Forms will run both when form.validate() is called. Calling form.commit() will run schema level validation by default, and can also run model validation if { validate: true } is passed.

In other words, I believe the validate flag is specifically designed to mirror / pass through to Backbone's set (whose option is described on http://backbonejs.org/#Model-validate). So yes, I think it was intentional this way and it would definitely a backwards incompatible change for validate: false to suddenly also ignore schema-level validation.

If this behavior is really needed, perhaps introducing another option (e.g. schemaValidate) would be better, though I'd question why you bother with form/schema validation if you want to disable it.

from backbone-forms.

hcharley avatar hcharley commented on June 12, 2024

@philfreo Thanks for breaking it down for me. I thought there was an intent that I wasn't picking up on.

My usecase is this:

I want to show users a rendered preview of their form values as they input data. Like a WYSIWG. (e.g. insert a headline in a form input, have it show up in a "preview pane" inside an <h1> tag).

I have a slug field that I definitely want to validate on form submission, but I don't care about whether or not it's valid before then. The slug doesn't show up in the preview pane.

So if the slug fails validation, I still want to be able to commit other values, like headline, to the model so that they get rendered on the preview. I don't want one invalid field to break my entire preview pane.

On form submit, I will definitely validate and prevent submission if there are invalid fields.

from backbone-forms.

philfreo avatar philfreo commented on June 12, 2024

One idea is to move slug validation to the Backbone model then. Or have a selective backbone-forms validator that only gets triggered when a certain criteria (final submission) is true.

from backbone-forms.

hcharley avatar hcharley commented on June 12, 2024

I think I see what you're getting at. It's an anti-pattern to commit dirty data to the model, and in a sense defeats the purpose of having validation schemas in the first place. Perhaps, I am the only exception who would like to commit dirty data to my model.

However, I'm not a big fan of moving validation to the Backbone model's validate, as I lose out on backbone-form's schema pattern, which I really prefer, and ultimately on final submission, I want to use.

Also, moving to a custom validator would be alright, but in practice, I'll probably end up writing custom validators for all my fields and then would have to lay some more code on to determine the state of a commit (final submission vs. preview render). So I'd either have to abstract Backbone-Form's validators or rewrite them.

I'm going to submit a PR to see if there are thoughts on adding an option to form.commit().

from backbone-forms.

0xgeert avatar 0xgeert commented on June 12, 2024

from backbone-forms.

0xgeert avatar 0xgeert commented on June 12, 2024

from backbone-forms.

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.