8000 Fixes recursive loop if model attributes contain nested models by asgeo1 · Pull Request #97 · thedersen/backbone.validation · GitHub
[go: up one dir, main page]

Skip to content

Fixes recursive loop if model attributes contain nested models #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

asgeo1
Copy link
Contributor
@asgeo1 asgeo1 commented Jan 17, 2013

I.e. nested models created from the backbone-relational plugin

I.e. nested models created from the backbone-relational plugin
@thedersen
Copy link
Owner

Thanks for the pull. We have a discussion going on in #93 regarding this. Feel free to join it:-)

@azproduction
Copy link

Better way to fix that is

    if (obj instanceof Backbone.Model || obj instanceof Backbone.Collection) {
        obj = obj.toJSON();
    }

Why?

I have an model in that model there is sub-model as Array that represents a GeoPoint like this [0.0, 0.0]. I can't skip values of that object, because of validator

// Specify validator
_.extend(Backbone.Validation.validators, {
    point: function(value, attr, customValue, model) {
        var isValid = _.isArray(value) &&
            value.length === 2 &&
            typeof value[0] === 'number' &&
            typeof value[1] === 'number';

        if (!isValid) {
            return 'It should be geo point';
        }
    }
});

@azproduction
Copy link

There is also can be a case when someone is required to validate sub-models... so obj.toJSON prolly is not the solution

@kayhadrin
Copy link

FWIW, toJSON does not transform sub-models into plain JSON automatically.

@sdeleuze
Copy link
sdeleuze commented Jun 6, 2013

@thedersen There has been no update of this plugin for 5 months. It would be awesome if you could make a release at least with the current "important pull request" (this one, #125) + Backbone 1.0 compatibility.

Is it possible ?

@wulftone
Copy link
wulftone commented Jun 6, 2013

I dunno if we'll hear from @thedersen anytime soon, so I went ahead and found this plugin which does all the validation I personally need, and the maintainer has been very responsive.

@sdeleuze
Copy link
sdeleuze commented Jun 6, 2013

@wulftone Thanks for sharing. Is it hard to switch ?

8000

@wulftone
Copy link
wulftone commented Jun 6, 2013

I didn't think it was hard, but then again, I didn't have a lot of models to validate. The two plugins work largely the same, though the mechanism for triggering events is a little different. The source code is really easy to read, and the plugin manages to do much of the same as this one, but is about 5/8ths as large (5.2kb min, 8.2kb min). Being that it's smaller, it's also pretty easy to grok and extend.

@thedersen
Copy link
Owner

I'm sorry I have not had the time to follow up this project as much as I would like to. Hopefully I will get to spend some time fixing these issues in the next couple of weeks.

@sdeleuze
Copy link
sdeleuze commented Jun 7, 2013

That's good news thanks !!!

thedersen added a commit that referenced this pull request Jun 10, 2013
@thedersen
Copy link
Owner

I have now merged this. Hopefully this fixes some of the issues you are having.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0