Comments (4)
@vswaminathan Thanks for all of the feedback.
Good catch on (1) - I pushed that into master.
Regarding (2) - a select option value may be an object which cannot be pushed into an option value attribute. Instead, the value is cached in data. Stickit configures bindings for select options so you really shouldn't need to get the value from the DOM - the model is bound and I would count on it to contain the truth. If you want to manually look through the DOM for an option value, you can get it out of the data:
$('#my-select option:selected').data('stickit_bind_val');
Regarding (3) - your use case sounds very particular to your setup and how you are running validations. That said, I think that stickit should be as general as possible, so I'm willing to consider a change to support flexibility like this. Can you give me examples of what additions you would like to see in the api and how it would work?
from backbone.stickit.
Thanks, Regarding 3, Here is the use case. Let us say there is a model "User" with attributes like name, age, email etc. There is a form to add/ edit User information. There is a template (underscore template) for this form, bound to this model. The model has validation rules in the validate method of the backbone model. In Stickit, the data is "set" on keypress up as each character is typed in (in a text box) . Since the field data is not complete, the validation fails (for example an email address) and the "set" fails. So characters typed in a field gets reset and the user is not able to complete the entry. The other problem is, if there is a list view associated with this model , like a list of users, the view gets updated as the form is edited by the user, not a good user experience,as the data entry is not complete and the input is not validated.
So here is my suggestion to add to the API. Each binding can have an option as to when the change to the attribute should be "set" to the underlying model. It could be an event that triggers the set. Some thing like this "setModelOn: "click #formSubmit".
from backbone.stickit.
@vswaminathan I like the general flexibility you are trying to add but I want to keep form elements bound with model attributes, and not have a general form submission/binding handling.
For your project use case, I would suggest two validation functions - one that is called in real-time (this can make checks to ensure alpha-numeracy, etc.) and can report errors immediately, and another validation routine which is called on form submission/save which can make sure email addresses are tidy and fields exists, etc.
I've done this in the past and it has worked out well.
To support flexibility, I have been considering adding a configuration that will let you specify an event type and an optional callback handler.
from backbone.stickit.
@vswaminathan Thanks again for the help. I'm closing this and opening a new issue regarding custom event bindings. Please chime in with any ideas in issue #13.
from backbone.stickit.
Related Issues (20)
- Support falsy values in classes binding HOT 3
- [Suggestion] "name=" selector HOT 5
- Change Event Fires Twice for Number Input Type HOT 3
- events: ["keyup"] in ie8 HOT 1
- Using equality operator instead of identity operator for select field HOT 2
- bind the model with backbone variable HOT 3
- Confusing `updateModel` name HOT 4
- Problems with defaultOption as a function, returning false
- Make 'updateModel' supporting Promise? HOT 3
- Make compatible with Lodash v4 HOT 2
- IE7 input change events
- The bindings crashed in IE11 and Edge checkbox
- Dependent select HOT 1
- Sorting select options
- bblatest branch / listenTo refactor question
- Deselecting multpile checkboxes don't run validation.
- Is this project still alive? HOT 3
- Maintainer Needed HOT 1
- Multiple DOM elements with matching ID's - is this legal? HOT 2
- Loss of context in onGet() function HOT 4
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.stickit.