Comments (6)
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.
@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.
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.
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.
from backbone-forms.
from backbone-forms.
Related Issues (20)
- Code mismatch between github and NPM registry HOT 2
- lodash 4.x support HOT 1
- itemToString does not escape values by default HOT 3
- Memory leak in Form.editors.List.setValue() HOT 7
- Form.Editor.validate() reads all form values for nothing HOT 2
- $ not declared in Form.validators
- Make list works with Backbone Collection
- 0.15.0 milestone HOT 2
- Select._getOptionsHtml/arrayToHTML is very slow
- Bootstrap 3 inline radio / checkbox items
- Disabling fields: use $.prop rather than $.attr
- submodule in npm HOT 1
- Cannot read property 'render' of undefined HOT 1
- Submitting the form by pressing "enter" on a Number editor doesn't work
- reasons bb-forms is still fixed to bb ~1.2? HOT 4
- How do I load List editor with webpack/browerify? HOT 1
- Number cannot accept negative values HOT 1
- [QUESTION] Where I can find the CI service?
- setOptions not working in select editor when function is used.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone-forms.