Giter Site home page Giter Site logo

Comments (4)

delambo avatar delambo commented on August 31, 2024

@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.

vswaminathan avatar vswaminathan commented on August 31, 2024

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.

delambo avatar delambo commented on August 31, 2024

@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.

delambo avatar delambo commented on August 31, 2024

@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)

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.